diff --git a/plugins/decman-pacman/tests/test_decman_plugins_pacman.py b/plugins/decman-pacman/tests/test_decman_plugins_pacman.py index 1fee01c..911fb82 100644 --- a/plugins/decman-pacman/tests/test_decman_plugins_pacman.py +++ b/plugins/decman-pacman/tests/test_decman_plugins_pacman.py @@ -195,7 +195,7 @@ def test_apply_returns_false_on_command_failure(monkeypatch: pytest.MonkeyPatch) pass def get_native_explicit(self) -> set[str]: - raise pacman_plugin.errors.CommandFailedError(["get_native_explicit"], "boom") + raise pacman_plugin.errors.CommandFailedError(["get_native_explicit"], 10, "boom") monkeypatch.setattr(pacman_plugin, "PacmanInterface", FailingPM) diff --git a/src/decman/core/command.py b/src/decman/core/command.py index 7a5be44..8170316 100644 --- a/src/decman/core/command.py +++ b/src/decman/core/command.py @@ -218,9 +218,9 @@ def check_run_result( code, output = result if code != 0: if include_output: - raise errors.CommandFailedError(command, output) + raise errors.CommandFailedError(command, code, output) else: - raise errors.CommandFailedError(command, None) + raise errors.CommandFailedError(command, code, None) return code, output diff --git a/src/decman/core/error.py b/src/decman/core/error.py index 1331171..9aef8c6 100644 --- a/src/decman/core/error.py +++ b/src/decman/core/error.py @@ -74,13 +74,17 @@ class CommandFailedError(Exception): Attributes: command (list[str]): The command that caused the exception. + exit_code (int): The exit code of the command output (str|None): Output of the command. """ - def __init__(self, command: list[str], output: str | None) -> None: + def __init__(self, command: list[str], exit_code: int, output: str | None) -> None: self.command = shlex.join(command) + self.exit_code = exit_code if output: self.output: str | None = output.strip() else: self.output = None - super().__init__(f"Command '{self.command}' returned with a non-zero exit code.") + super().__init__( + f"Command '{self.command}' returned with a non-zero exit code {self.exit_code}." + ) diff --git a/src/decman/extras/gpg.py b/src/decman/extras/gpg.py index 33a8fbc..8a96046 100644 --- a/src/decman/extras/gpg.py +++ b/src/decman/extras/gpg.py @@ -100,6 +100,7 @@ class _GPGInterface: "--no-tty", "--import-ownertrust", ] + # use subprocess manually since decman exposed functions don't allow setting input p = subprocess.run( cmd, input=data, @@ -110,7 +111,7 @@ class _GPGInterface: check=False, ) if p.returncode != 0: - raise CommandFailedError(cmd, p.stdout) + raise CommandFailedError(cmd, p.returncode, p.stdout) def delete_keys(self, fingerprints: list[str]): decman.prg(