From fcb2a3982b24613b38f6ed02c31f59bc441f5a79 Mon Sep 17 00:00:00 2001 From: Matthew Newville Date: Sat, 14 Sep 2024 11:08:55 -0500 Subject: [PATCH] emergency fix for handling errors, exposed by lmfit --- asteval/asteval.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/asteval/asteval.py b/asteval/asteval.py index 2b84e1e..278b15f 100644 --- a/asteval/asteval.py +++ b/asteval/asteval.py @@ -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 @@ -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: