Skip to content

Commit

Permalink
Merge pull request #790 from qutech/doc/better_deserializarion_error
Browse files Browse the repository at this point in the history
Give an exception with more context if deserialization fails
  • Loading branch information
terrorfisch authored Aug 29, 2023
2 parents f3ae05e + 6d1e3f9 commit e86613c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion qupulse/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,11 @@ def filter_serializables(self, obj_dict) -> Any:
if get_default_pulse_registry() is self.storage:
registry = dict()

return deserialization_callback(identifier=obj_identifier, registry=registry, **obj_dict)
try:
return deserialization_callback(identifier=obj_identifier, registry=registry, **obj_dict)
except Exception as err:
raise ValueError(f"Unable to deserialize {type_identifier} from {obj_dict}",
type_identifier, obj_dict) from err
return obj_dict


Expand Down
5 changes: 4 additions & 1 deletion tests/serialization_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,9 +1051,12 @@ def test_deserialize_storage_is_not_default_registry_id_occupied(self) -> None:
del pulse_storage

pulse_storage = PulseStorage(backend)
with self.assertRaisesRegex(RuntimeError, "Pulse with name already exists"):
with self.assertRaises(ValueError) as cm:
pulse_storage['peter']

# this is shitty
self.assertIsInstance(cm.exception.__cause__, RuntimeError)

def test_deserialize_twice_same_object_storage_is_default_registry(self) -> None:
backend = DummyStorageBackend()

Expand Down

0 comments on commit e86613c

Please sign in to comment.