Skip to content

Commit

Permalink
Fix solver exception handling
Browse files Browse the repository at this point in the history
Avoid UnboundLocalError in case solver execution throws an exception.
Information about the solver error is now passed within the
exception message.

fix ahellander#157
  • Loading branch information
Aratz committed Nov 2, 2016
1 parent ec6eac9 commit 0eab5bd
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions pyurdme/pyurdme.py
Original file line number Diff line number Diff line change
Expand Up @@ -2366,19 +2366,21 @@ def run(self, number_of_trajectories=1, seed=None, input_file=None, loaddata=Fal
handle = subprocess.Popen(urdme_solver_cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
stdout, stderr = handle.communicate()
return_code = handle.wait()
except OSError as e:
print "Error, execution of solver raised an exception: {0}".format(e)
print "urdme_solver_cmd = {0}".format(urdme_solver_cmd)

if return_code != 0:
if self.report_level >= 1:
try:
if return_code != 0:
if self.report_level >= 1:
print stderr, stdout
except Exception as e:
pass
print "urdme_solver_cmd = {0}".format(urdme_solver_cmd)
raise URDMEError("Solver execution failed, return code = {0}".format(return_code))

raise URDMEError(
"Solver execution failed, return code = {0}".format(return_code) +
"\nurdme_solver_cmd = {0}".format(urdme_solver_cmd)
)
except OSError as e:
# Add urdme command to exception message
raise URDMEError(
str(e) +
"\nurdme_solver_cmd = {0}".format(urdme_solver_cmd)
)
print e.args
raise e

#Load the result from the hdf5 output file.
try:
Expand Down

0 comments on commit 0eab5bd

Please sign in to comment.