Skip to content

Commit

Permalink
emergency fix for handling errors, exposed by lmfit
Browse files Browse the repository at this point in the history
  • Loading branch information
newville committed Sep 14, 2024
1 parent 1f135fa commit fcb2a39
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion asteval/asteval.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ def raise_exception(self, node, exc=None, msg='', expr=None,
self.error_msg = f"{exc:s}: {msg}"
if exc is None:
exc = self.error[-1].exc
if exc is None and len(self.error) > 0:
while exc is None and len(self.error) > 0:
err = self.error.pop()
exc = err.exc
if exc is None:
exc = Exception
raise exc(self.error_msg)

# main entry point for Ast node evaluation
Expand Down Expand Up @@ -328,7 +334,7 @@ def eval(self, expr, lineno=0, show_errors=True, raise_errors=False):
else:
node = expr
try:
return self.run(node, expr=expr, lineno=lineno)
return self.run(node, expr=expr, lineno=lineno, with_raise=raise_errors)
except:
errmsg = exc_info()[1]
if len(self.error) > 0:
Expand Down

0 comments on commit fcb2a39

Please sign in to comment.