mirror of
https://github.com/kiviktnm/decman.git
synced 2026-09-19 12:08:28 +00:00
Merge pull request #50 from kiviktnm/feat/print-failed-command-exit-code
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
|
pass
|
||||||
|
|
||||||
def get_native_explicit(self) -> set[str]:
|
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)
|
monkeypatch.setattr(pacman_plugin, "PacmanInterface", FailingPM)
|
||||||
|
|
||||||
|
|||||||
@@ -218,9 +218,9 @@ def check_run_result(
|
|||||||
code, output = result
|
code, output = result
|
||||||
if code != 0:
|
if code != 0:
|
||||||
if include_output:
|
if include_output:
|
||||||
raise errors.CommandFailedError(command, output)
|
raise errors.CommandFailedError(command, code, output)
|
||||||
else:
|
else:
|
||||||
raise errors.CommandFailedError(command, None)
|
raise errors.CommandFailedError(command, code, None)
|
||||||
return code, output
|
return code, output
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -74,13 +74,17 @@ class CommandFailedError(Exception):
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
command (list[str]): The command that caused the exception.
|
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.
|
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.command = shlex.join(command)
|
||||||
|
self.exit_code = exit_code
|
||||||
if output:
|
if output:
|
||||||
self.output: str | None = output.strip()
|
self.output: str | None = output.strip()
|
||||||
else:
|
else:
|
||||||
self.output = None
|
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",
|
"--no-tty",
|
||||||
"--import-ownertrust",
|
"--import-ownertrust",
|
||||||
]
|
]
|
||||||
|
# use subprocess manually since decman exposed functions don't allow setting input
|
||||||
p = subprocess.run(
|
p = subprocess.run(
|
||||||
cmd,
|
cmd,
|
||||||
input=data,
|
input=data,
|
||||||
@@ -110,7 +111,7 @@ class _GPGInterface:
|
|||||||
check=False,
|
check=False,
|
||||||
)
|
)
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
raise CommandFailedError(cmd, p.stdout)
|
raise CommandFailedError(cmd, p.returncode, p.stdout)
|
||||||
|
|
||||||
def delete_keys(self, fingerprints: list[str]):
|
def delete_keys(self, fingerprints: list[str]):
|
||||||
decman.prg(
|
decman.prg(
|
||||||
|
|||||||
Reference in New Issue
Block a user