core: broaden error catching for propertymappings

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-07-21 22:50:39 +02:00
parent e62f5a75e4
commit b3da94bbb8
2 changed files with 4 additions and 4 deletions

View file

@ -491,8 +491,8 @@ class PropertyMapping(SerializerModel, ManagedModel):
evaluator.set_context(user, request, self, **kwargs)
try:
return evaluator.evaluate(self.expression)
except (ValueError, SyntaxError) as exc:
raise PropertyMappingExpressionException from exc
except Exception as exc:
raise PropertyMappingExpressionException(str(exc)) from exc
def __str__(self):
return f"Property Mapping {self.name}"

View file

@ -31,7 +31,7 @@ class TestPropertyMappings(TestCase):
"""Test expression error"""
expr = "return aaa"
mapping = PropertyMapping.objects.create(name="test", expression=expr)
with self.assertRaises(NameError):
with self.assertRaises(PropertyMappingExpressionException):
mapping.evaluate(None, None)
events = Event.objects.filter(
action=EventAction.PROPERTY_MAPPING_EXCEPTION, context__expression=expr
@ -44,7 +44,7 @@ class TestPropertyMappings(TestCase):
expr = "return aaa"
request = self.factory.get("/")
mapping = PropertyMapping.objects.create(name="test", expression=expr)
with self.assertRaises(NameError):
with self.assertRaises(PropertyMappingExpressionException):
mapping.evaluate(get_anonymous_user(), request)
events = Event.objects.filter(
action=EventAction.PROPERTY_MAPPING_EXCEPTION, context__expression=expr