If a custom deserialisation function threw a TypeError, it was very hard to find out what was wrong, because the error was caught in a try-except-block. The try was intended to catch when the current class is being loaded with the wrong arguments, but it was also catching (and obfuscating) when a TypeError was raised during construction of the arguments themselves.
Example code that caused this (I would make it a test in this PR but it uses numpy and msg pack so could not be included)
File "/Users/peter/projects/eagle_eyes/src/eagle_eyes_video_scanner/src/dataclasses-serialization/dataclasses_serialization/serializer_base/dataclasses.py", line 39, in dict_to_dataclass
raise DeserializationError(
dataclasses_serialization.serializer_base.errors.DeserializationError: Missing one or more required fields to deserialize {'database': {364226: {'name': 'Nancy', 'img': b"\x85\xc4\x02nd\xc3\xc4\x04type\xa3|u1\xc4\x04kind\xc4\x00\xc4\x05shape\x93\x04\x03\x03\xc4\x04data\xc4$\xd0\xbd5\xfdR^\xcc\xb4P3\xe7\x05m\x02\x9a\x16X\xc0\xeb\xf9\xdc\x1b\x9d\xb4\xdd>\x06\xe3\x81\xedF\x08\x9d\xd8X'"}, 32532234: {'name': 'Abdul', 'img': b"\x85\xc4\x02nd\xc3\xc4\x04type\xa3|u1\xc4\x04kind\xc4\x00\xc4\x05shape\x93\x04\x03\x03\xc4\x04data\xc4$\x99'N\x91+\xa0/^\x13S\xc6\x08\x17M\x97\xa4\xe7\xcbv\x19\xc7\xc6O\xa6\xdd\xa0\xf0\xc6\x97R\xde\x90\x8b\x8fF\xbd"}}} as <class '__main__.TheBookOfFaces'>
After the fix, it raised a much more clear message which indicated the problem.
File "/Users/peter/projects/eagle_eyes/src/eagle_eyes_video_scanner/src/dataclasses-serialization/dataclasses_serialization/serializer_base/serializer.py", line 66, in deserialize
return deserialization_func(cls, serialized_obj)
TypeError: unpackb() takes 1 positional argument but 2 were given
Which helped make the fix, which was simply to change the line to
If a custom deserialisation function threw a
TypeError
, it was very hard to find out what was wrong, because the error was caught in a try-except-block. The try was intended to catch when the current class is being loaded with the wrong arguments, but it was also catching (and obfuscating) when aTypeError
was raised during construction of the arguments themselves.Example code that caused this (I would make it a test in this PR but it uses numpy and msg pack so could not be included)
Before the fix, it raised the very unclear
After the fix, it raised a much more clear message which indicated the problem.
Which helped make the fix, which was simply to change the line to