Skip to content

Commit 327246f

Browse files
authored
Merge pull request #557 from stan-dev/improve-error-detection
Detect failures in generated quantities
2 parents f2616ae + 20effee commit 327246f

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

cmdstanpy/model.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,10 +1175,13 @@ def sample(
11751175
" force_one_process_per_chain to True"
11761176
)
11771177

1178-
if not runset._check_retcodes():
1179-
msg = 'Error during sampling:\n{}'.format(runset.get_err_msgs())
1180-
msg = '{}Command and output files:\n{}'.format(
1181-
msg, runset.__repr__()
1178+
errors = runset.get_err_msgs()
1179+
if errors or not runset._check_retcodes():
1180+
msg = (
1181+
f'Error during sampling:\n{errors}\n'
1182+
+ f'Command and output files:\n{repr(runset)}\n'
1183+
+ 'Consider re-running with show_console=True if the above'
1184+
+ ' output is unclear!'
11821185
)
11831186
raise RuntimeError(msg)
11841187

@@ -1317,12 +1320,13 @@ def generate_quantities(
13171320
show_console=show_console,
13181321
)
13191322

1320-
if not runset._check_retcodes():
1321-
msg = 'Error during generate_quantities:\n{}'.format(
1322-
runset.get_err_msgs()
1323-
)
1324-
msg = '{}Command and output files:\n{}'.format(
1325-
msg, runset.__repr__()
1323+
errors = runset.get_err_msgs()
1324+
if errors:
1325+
msg = (
1326+
f'Error during generate_quantities:\n{errors}\n'
1327+
+ f'Command and output files:\n{repr(runset)}\n'
1328+
+ 'Consider re-running with show_console=True if the above'
1329+
+ ' output is unclear!'
13261330
)
13271331
raise RuntimeError(msg)
13281332
quantities = CmdStanGQ(runset=runset, mcmc_sample=mcmc_fit)

0 commit comments

Comments
 (0)