Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions azure/functions/durable_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ def decode(cls,
except json.JSONDecodeError:
# String failover if the content is not json serializable
result = data.value
except Exception:
except Exception as e:
raise ValueError(
'activity trigger input must be a string or a '
f'valid json serializable ({data.value})')
f'valid json serializable ({data.value})') from e
else:
raise NotImplementedError(
f'unsupported activity trigger payload type: {data_type}')
Expand All @@ -115,9 +115,9 @@ def encode(cls, obj: typing.Any, *,
try:
callback = _durable_functions._serialize_custom_object
result = json.dumps(obj, default=callback)
except TypeError:
except TypeError as e:
raise ValueError(
f'activity trigger output must be json serializable ({obj})')
f'activity trigger output must be json serializable ({obj})') from e

return meta.Datum(type='json', value=result)

Expand Down
24 changes: 24 additions & 0 deletions tests/test_durable_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ def test_activity_trigger_encode(self):
expected_type=type(datum['output']))
self.assertEqual(encoded, datum['expected_value'])

def test_activity_trigger_encode_failure_exception_has_cause(self):
class NonEncodable:
def __init__(self):
self.value = 'foo'

data = NonEncodable()

try:
ActivityTriggerConverter.encode(data, expected_type=None)
except ValueError as e:
self.assertIsNotNone(e.__cause__)
self.assertIsInstance(e.__cause__, TypeError)

def test_activity_trigger_decode(self):
# Activity Trigger allow inputs to be any JSON serializables
# The input values to the trigger should be passed into arguments
Expand Down Expand Up @@ -209,6 +222,17 @@ def test_activity_trigger_decode(self):
trigger_metadata=None)
self.assertEqual(decoded, datum['expected_value'])

def test_activity_trigger_decode_failure_exception_has_cause(self):
data = Datum('{"value": "bar"}', 'json')

try:
ActivityTriggerConverter.decode(
data=data,
trigger_metadata=None)
except ValueError as e:
self.assertIsNotNone(e.__cause__)
self.assertIsInstance(e.__cause__, TypeError)

def test_activity_trigger_has_implicit_return(self):
self.assertTrue(
ActivityTriggerConverter.has_implicit_output()
Expand Down