Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give an exception with more context if deserialization fails #790

Merged
merged 2 commits into from
Aug 29, 2023
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
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
Loading