mirror of
https://github.com/kiviktnm/decman.git
synced 2026-09-19 12:08:28 +00:00
Include exit code in CommandFailedError
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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}."
|
||||
)
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user