From 2b19fc82352aebc8b976229921252dd3a2c5169b Mon Sep 17 00:00:00 2001 From: Till Hoffmann Date: Fri, 9 Feb 2024 18:36:12 -0500 Subject: [PATCH] Show `stdout` and `stderr` for non-zero return codes. --- cmdstanpy/model.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmdstanpy/model.py b/cmdstanpy/model.py index 5add5704..cd6e284f 100644 --- a/cmdstanpy/model.py +++ b/cmdstanpy/model.py @@ -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 " @@ -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)