lib: fix stacktrace for general expressions

This commit is contained in:
Jens Langhammer 2021-02-08 22:14:13 +01:00
parent 1a619c90de
commit e555bdd42b
2 changed files with 4 additions and 4 deletions

View file

@ -98,6 +98,10 @@ class BaseEvaluator:
exec(ast_obj, self._globals, _locals) # nosec # noqa
result = _locals["result"]
except Exception as exc:
# So, this is a bit questionable. Essentially, we are edit the stacktrace
# so the user only sees information relevant to them
# and none of our surrounding error handling
exc.__traceback__ = exc.__traceback__.tb_next
self.handle_error(exc, expression_source)
raise exc
return result

View file

@ -55,10 +55,6 @@ class PolicyEvaluator(BaseEvaluator):
def handle_error(self, exc: Exception, expression_source: str):
"""Exception Handler"""
# So, this is a bit questionable. Essentially, we are edit the stacktrace
# so the user only sees information relevant to them
# and none of our surrounding error handling
exc.__traceback__ = exc.__traceback__.tb_next
raise PolicyException(exc)
def evaluate(self, expression_source: str) -> PolicyResult: