Skip to content

Commit e6d6867

Browse files
committed
Capture stderr
1 parent bc0787b commit e6d6867

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/bioontologies/robot.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ def call_robot(args: list[str]) -> str:
9595
ret = check_output( # noqa:S603
9696
rr,
9797
cwd=os.path.dirname(__file__),
98+
stderr=subprocess.PIPE,
9899
)
99100
except subprocess.CalledProcessError as e:
100101
raise ROBOTError(
101102
command=e.cmd,
102103
return_code=e.returncode,
103104
output=e.output.decode() if e.output is not None else None,
105+
stderr=e.stderr.decode() if e.stderr is not None else None
104106
) from None
105107

106108
return ret.decode()
@@ -483,6 +485,7 @@ def __init__(
483485
command: list[str],
484486
return_code: int,
485487
output: str | None = None,
488+
stderr: str | None = None,
486489
preview_length: int = 500,
487490
) -> None:
488491
"""Initialize a wrapper around a ROBOT exception.
@@ -499,16 +502,19 @@ def __init__(
499502
"""
500503
self.command = command
501504
self.return_code = return_code
502-
self.output = output or "<no output>"
505+
self.stdout = output or "<no stdout>"
503506
self.preview_length = preview_length
507+
self.stderr = stderr or "<no stderr>"
504508

505509
# Create the error message
506510
command_str = " ".join(command)
507-
output_preview = textwrap.indent(textwrap.shorten(self.output, preview_length), " ")
511+
stdout_preview = textwrap.indent(textwrap.shorten(self.stdout, preview_length), " ")
512+
stderr_preview = textwrap.indent(textwrap.shorten(self.stderr, preview_length), " ")
508513

509514
message = (
510515
f"Command `{command_str}` returned non-zero exit status {return_code}.\n\n"
511-
f"Output:\n\n{output_preview}"
516+
f"stderr:\n\n{stderr_preview}"
517+
f"\n\nstdout:\n\n{stdout_preview}"
512518
)
513519

514520
super().__init__(message)

0 commit comments

Comments
 (0)