Skip to content

Commit

Permalink
Catch arithmetic errors as evaluation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroSteiner committed Feb 9, 2025
1 parent cac26b3 commit dd845b4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/rule_engine/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,13 @@ def __op_arithmetic(self, op, thing):
_assert_is_numeric(left_value)
right_value = self.right.evaluate(thing)
_assert_is_numeric(right_value)
return op(left_value, right_value)
try:
result = op(left_value, right_value)
except ZeroDivisionError:
raise errors.EvaluationError('arithmetic error: division by zero') from None
except ArithmeticError:
raise errors.EvaluationError('arithmetic error') from None
return result

_op_fdiv = functools.partialmethod(__op_arithmetic, operator.floordiv)
_op_tdiv = functools.partialmethod(__op_arithmetic, operator.truediv)
Expand Down

0 comments on commit dd845b4

Please sign in to comment.