Skip to content

Commit

Permalink
add more detailed errors for failed subprocesses
Browse files Browse the repository at this point in the history
The error message now includes the stdout/stderr of the failed process,
if available.
  • Loading branch information
ArkaneMoose committed Apr 23, 2023
1 parent ff2749d commit d6a0225
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions backend/lightningsim/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,19 @@ def command(self):
return shlex.join(self.args)

def check_returncode(self):
if self.returncode != 0:
raise RuntimeError(
f"command {self.command} returned non-zero exit status {self.returncode}"
)
if self.returncode == 0:
return
message = (
f"command {self.command} "
f"returned non-zero exit status {self.returncode}"
)
if self.output:
line_prefix = "> "
formatted_output = self.output.rstrip("\n")
formatted_output = formatted_output.replace("\n", f"\n{line_prefix}")
formatted_output = line_prefix + formatted_output
message += f" with output:\n{formatted_output}"
raise RuntimeError(message)


async def run(args: Sequence[str | Path], check=False, **kwargs):
Expand Down

0 comments on commit d6a0225

Please sign in to comment.