Skip to content

Commit de998c4

Browse files
committed
Log errors on docker run/exec failure
1 parent c135254 commit de998c4

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

tagging/utils/docker_runner.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def exec_cmd(container: Container, cmd: str) -> str:
4747
exec_result = container.exec_run(cmd)
4848
output = exec_result.output.decode().rstrip()
4949
assert isinstance(output, str)
50-
LOGGER.debug(f"Command output: {output}")
51-
assert exec_result.exit_code == 0, f"Command: `{cmd}` failed"
50+
if exec_result.exit_code != 0:
51+
LOGGER.error(f"Command output:\n{output}")
52+
raise AssertionError(f"Command: `{cmd}` failed")
53+
else:
54+
LOGGER.debug(f"Command output:\n{output}")
5255
return output

tests/utils/tracked_container.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ def exec_cmd(self, cmd: str, **kwargs: Any) -> str:
7575
exec_result = container.exec_run(cmd, **final_kwargs)
7676
output = exec_result.output.decode().rstrip()
7777
assert isinstance(output, str)
78-
LOGGER.debug(f"Command output: {output}")
79-
assert exec_result.exit_code == 0, f"Command: `{cmd}` failed"
78+
if exec_result.exit_code != 0:
79+
LOGGER.error(f"Command output:\n{output}")
80+
raise AssertionError(f"Command: `{cmd}` failed")
81+
else:
82+
LOGGER.debug(f"Command output:\n{output}")
8083
return output
8184

8285
def run_and_wait(
@@ -91,10 +94,15 @@ def run_and_wait(
9194
assert self.container is not None
9295
rv = self.container.wait(timeout=timeout)
9396
logs = self.get_logs()
94-
LOGGER.debug(logs)
97+
failed = rv["StatusCode"] != 0
98+
99+
if failed:
100+
LOGGER.error(f"Command output:\n{logs}")
101+
else:
102+
LOGGER.debug(f"Command output:\n{logs}")
103+
assert no_failure != failed
95104
assert no_warnings == (not self.get_warnings(logs))
96105
assert no_errors == (not self.get_errors(logs))
97-
assert no_failure == (rv["StatusCode"] == 0)
98106
self.remove()
99107
return logs
100108

0 commit comments

Comments
 (0)