Skip to content

Commit

Permalink
Show stdout and stderr for non-zero return codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tillahoffmann committed Jul 10, 2024
1 parent f1cae03 commit 8f3d3b4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cmdstanpy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,11 @@ def diagnose(
cmd, capture_output=True, check=False, text=True
)
if proc.returncode:
get_logger().error(
"'diagnose' command failed!\nstdout:%s\nstderr:%s",
proc.stdout,
proc.stderr,
)
if require_gradients_ok:
raise RuntimeError(
"The difference between autodiff and finite difference "
Expand All @@ -2268,8 +2273,13 @@ def diagnose(
)

# Read the text and get the last chunk separated by a single # char.
with open(output) as handle:
text = handle.read()
try:
with open(output) as handle:
text = handle.read()
except FileNotFoundError as exc:
raise RuntimeError(
"Output of 'diagnose' command does not exist."
) from exc
*_, table = re.split(r"#\s*\n", text)
table = (
re.sub(r"^#\s*", "", table, flags=re.M)
Expand Down

0 comments on commit 8f3d3b4

Please sign in to comment.