@@ -92,6 +92,36 @@ def _process_CLI_arguments(volume=False, geometry_debug=False, particles=None,
9292 return args
9393
9494
95+ def _get_error_message (output ):
96+ """Truncate a raised exception message from C++ to be applied as a Python exception message
97+
98+ Parameters
99+ ----------
100+ output : str
101+ Standard output and standard error of the OpenMC executable
102+
103+ Returns
104+ -------
105+ str
106+ Error message to be applied as Exception text
107+
108+ """
109+ if 'ERROR: ' in output :
110+ _ , _ , error_msg = output .partition ('ERROR: ' )
111+ elif 'what()' in output :
112+ _ , _ , error_msg = output .partition ('what(): ' )
113+ elif 'terminating due to uncaught exception of type ' in output :
114+ # libc++ (e.g. macOS) reports "...of type std::runtime_error: msg"
115+ _ , _ , error_msg = output .partition (
116+ 'terminating due to uncaught exception of type ' )
117+ _ , sep , error_msg = error_msg .partition (': ' )
118+ if not sep or not error_msg .strip ():
119+ error_msg = 'OpenMC aborted unexpectedly.'
120+ else :
121+ error_msg = 'OpenMC aborted unexpectedly.'
122+ return ' ' .join (error_msg .split ())
123+
124+
95125def _run (args , output , cwd ):
96126 # Launch a subprocess
97127 p = subprocess .Popen (args , cwd = cwd , stdout = subprocess .PIPE ,
@@ -113,17 +143,7 @@ def _run(args, output, cwd):
113143
114144 # Raise an exception if return status is non-zero
115145 if p .returncode != 0 :
116- # Get error message from output and simplify whitespace
117- output = '' .join (lines )
118- if 'ERROR: ' in output :
119- _ , _ , error_msg = output .partition ('ERROR: ' )
120- elif 'what()' in output :
121- _ , _ , error_msg = output .partition ('what(): ' )
122- else :
123- error_msg = 'OpenMC aborted unexpectedly.'
124- error_msg = ' ' .join (error_msg .split ())
125-
126- raise RuntimeError (error_msg )
146+ raise RuntimeError (_get_error_message ('' .join (lines )))
127147
128148
129149def plot_geometry (output = True , openmc_exec = 'openmc' , cwd = '.' , path_input = None ):
0 commit comments