mirror of
https://github.com/kiviktnm/decman.git
synced 2026-09-19 12:08:28 +00:00
Use print_command_output for CommandFailedError output
This commit is contained in:
@@ -120,8 +120,7 @@ def prg(
|
|||||||
if code != 0:
|
if code != 0:
|
||||||
output.print_warning(f"Command '{shlex.join(cmd)}' returned with an exit code {code}.")
|
output.print_warning(f"Command '{shlex.join(cmd)}' returned with an exit code {code}.")
|
||||||
if not pty:
|
if not pty:
|
||||||
for line in command_output.strip().split("\n"):
|
output.print_command_output(command_output)
|
||||||
output.print_continuation(line.strip())
|
|
||||||
|
|
||||||
return command_output
|
return command_output
|
||||||
|
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ def main():
|
|||||||
failed = True
|
failed = True
|
||||||
except errors.CommandFailedError as error:
|
except errors.CommandFailedError as error:
|
||||||
output.print_error(str(error))
|
output.print_error(str(error))
|
||||||
|
output.print_command_output(error.output)
|
||||||
output.print_traceback()
|
output.print_traceback()
|
||||||
failed = True
|
failed = True
|
||||||
except ValueError as error:
|
except ValueError as error:
|
||||||
|
|||||||
@@ -68,4 +68,4 @@ class CommandFailedError(Exception):
|
|||||||
def __init__(self, command: list[str], output: str) -> None:
|
def __init__(self, command: list[str], output: str) -> None:
|
||||||
self.command = shlex.join(command)
|
self.command = shlex.join(command)
|
||||||
self.output = output.strip()
|
self.output = output.strip()
|
||||||
super().__init__(f"Running a command '{self.command}' failed. Output:\n{self.output}")
|
super().__init__(f"Running a command '{self.command}' failed.")
|
||||||
|
|||||||
@@ -133,12 +133,12 @@ def print_debug(msg: str):
|
|||||||
print(f"{_tag()} {_gray('DEBUG')}: {msg}")
|
print(f"{_tag()} {_gray('DEBUG')}: {msg}")
|
||||||
|
|
||||||
|
|
||||||
def print_command_output(msg: str):
|
def print_command_output(command_output: str):
|
||||||
"""
|
"""
|
||||||
Prints command output without a DECMAN tag if debug messages are enabled.
|
Prints command output prefixed with a DECMAN tag.
|
||||||
"""
|
"""
|
||||||
if config.debug_output:
|
for line in command_output.strip().split("\n"):
|
||||||
print(msg)
|
print_continuation(line.strip())
|
||||||
|
|
||||||
|
|
||||||
# ─────────────────────────────
|
# ─────────────────────────────
|
||||||
|
|||||||
@@ -231,6 +231,7 @@ class AUR(plugins.Plugin):
|
|||||||
except errors.CommandFailedError as error:
|
except errors.CommandFailedError as error:
|
||||||
output.print_error("Running a AUR command failed.")
|
output.print_error("Running a AUR command failed.")
|
||||||
output.print_error(str(error))
|
output.print_error(str(error))
|
||||||
|
output.print_command_output(error.output)
|
||||||
output.print_traceback()
|
output.print_traceback()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ class Flatpak(plugins.Plugin):
|
|||||||
except errors.CommandFailedError as error:
|
except errors.CommandFailedError as error:
|
||||||
output.print_error("Running a flatpak command failed.")
|
output.print_error("Running a flatpak command failed.")
|
||||||
output.print_error(str(error))
|
output.print_error(str(error))
|
||||||
|
output.print_command_output(error.output)
|
||||||
output.print_traceback()
|
output.print_traceback()
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ class Pacman(plugins.Plugin):
|
|||||||
except errors.CommandFailedError as error:
|
except errors.CommandFailedError as error:
|
||||||
output.print_error("Running a pacman command failed.")
|
output.print_error("Running a pacman command failed.")
|
||||||
output.print_error(str(error))
|
output.print_error(str(error))
|
||||||
|
output.print_command_output(error.output)
|
||||||
output.print_traceback()
|
output.print_traceback()
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -179,6 +179,7 @@ class Systemd(plugins.Plugin):
|
|||||||
except errors.CommandFailedError as error:
|
except errors.CommandFailedError as error:
|
||||||
output.print_error("Running a systemd command failed.")
|
output.print_error("Running a systemd command failed.")
|
||||||
output.print_error(str(error))
|
output.print_error(str(error))
|
||||||
|
output.print_command_output(error.output)
|
||||||
output.print_traceback()
|
output.print_traceback()
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -191,14 +191,18 @@ def test_apply_returns_false_on_command_failure(monkeypatch: pytest.MonkeyPatch)
|
|||||||
def fake_print_traceback() -> None:
|
def fake_print_traceback() -> None:
|
||||||
traceback_called.append(True)
|
traceback_called.append(True)
|
||||||
|
|
||||||
|
def fake_print_continuation(msg: str) -> None:
|
||||||
|
continuations.append(msg)
|
||||||
|
|
||||||
monkeypatch.setattr(pacman_plugin.output, "print_error", fake_print_error)
|
monkeypatch.setattr(pacman_plugin.output, "print_error", fake_print_error)
|
||||||
monkeypatch.setattr(pacman_plugin.output, "print_traceback", fake_print_traceback)
|
monkeypatch.setattr(pacman_plugin.output, "print_traceback", fake_print_traceback)
|
||||||
|
monkeypatch.setattr(pacman_plugin.output, "print_continuation", fake_print_continuation)
|
||||||
|
|
||||||
ok = pacman.apply(store, dry_run=False)
|
ok = pacman.apply(store, dry_run=False)
|
||||||
|
|
||||||
assert ok is False
|
assert ok is False
|
||||||
assert any("pacman command failed" in msg for msg in errors_logged)
|
assert any("pacman command failed" in msg for msg in errors_logged)
|
||||||
assert any("boom" in msg for msg in errors_logged)
|
assert any("boom" in msg for msg in continuations)
|
||||||
assert traceback_called # at least once
|
assert traceback_called # at least once
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user