Skip to content

Commit 8b2bedf

Browse files
authored
Merge pull request #633 from posit-dev/worktree-dgoss-docker-exit-handling
Print Docker stderr in dgoss error output
2 parents c4f23bd + 6b075cf commit 8b2bedf

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

posit-bakery/posit_bakery/plugins/builtin/dgoss/errors.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ def __init__(
3030
def __str__(self) -> str:
3131
s = f"{self.message}\n"
3232
s += f" - Exit code: {self.exit_code}\n"
33-
s += f" - Command output: \n{textwrap.indent(self.dump_stdout(), ' ')}\n"
33+
stdout_dump = self.dump_stdout()
34+
if stdout_dump:
35+
s += f" - Command output:\n{textwrap.indent(stdout_dump, ' ')}\n"
36+
stderr_dump = self.dump_stderr(lines=50)
37+
if stderr_dump:
38+
s += f" - Error output:\n{textwrap.indent(stderr_dump, ' ')}\n"
3439
s += f" - Command executed: {' '.join(self.cmd)}\n"
3540
if self.metadata:
3641
s += " - Metadata:\n"

posit-bakery/test/plugins/builtin/dgoss/test_suite.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,27 @@ def fake_run(self, tasks, *, on_result=None):
161161
suite.run()
162162
assert captured["tasks"]
163163
assert all(t.timeout == 900 for t in captured["tasks"]) # default 900 from GossOptions
164+
165+
166+
class TestBakeryDGossError:
167+
def test_str_includes_stderr_when_present(self):
168+
err = BakeryDGossError(
169+
message="dgoss execution failed for image 'test-image'",
170+
tool_name="dgoss",
171+
cmd=["dgoss", "run", "test-image"],
172+
stdout=b"",
173+
stderr=b"Error response from daemon: pull access denied",
174+
exit_code=125,
175+
)
176+
assert "Error response from daemon" in str(err)
177+
178+
def test_str_omits_stderr_section_when_empty(self):
179+
err = BakeryDGossError(
180+
message="dgoss execution failed for image 'test-image'",
181+
tool_name="dgoss",
182+
cmd=["dgoss", "run", "test-image"],
183+
stdout=b'{"summary": {}}',
184+
stderr=b"",
185+
exit_code=1,
186+
)
187+
assert "Error output" not in str(err)

0 commit comments

Comments
 (0)