Skip to content

Commit dd845b4

Browse files
committed
Catch arithmetic errors as evaluation errors
1 parent cac26b3 commit dd845b4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/rule_engine/ast.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,13 @@ def __op_arithmetic(self, op, thing):
494494
_assert_is_numeric(left_value)
495495
right_value = self.right.evaluate(thing)
496496
_assert_is_numeric(right_value)
497-
return op(left_value, right_value)
497+
try:
498+
result = op(left_value, right_value)
499+
except ZeroDivisionError:
500+
raise errors.EvaluationError('arithmetic error: division by zero') from None
501+
except ArithmeticError:
502+
raise errors.EvaluationError('arithmetic error') from None
503+
return result
498504

499505
_op_fdiv = functools.partialmethod(__op_arithmetic, operator.floordiv)
500506
_op_tdiv = functools.partialmethod(__op_arithmetic, operator.truediv)

0 commit comments

Comments
 (0)