ProtoDeep
ProtoDeep copied to clipboard
guess_schema throwing exception
When input data can't be decoded by guess_schema
, (for example because it has a 'group' wire type,
it will thrown a TypeError: 'NoneType' object is not subscriptable
.
That seems like it should either throw a relevant error, or return None
.
What is the expected behavior on a failure case?
Minimal code to reproduce it:
from protodeep.lib import guess_schema
input_data = b'\x83\x01\x88\x01h\x84\x01\x92\x01\x02\x08i'
schema = guess_schema(data=input_data, bruteforce_index=0)
Hey, thanks for your issue ! You're right, it should throw a more relevent error. I think I'll make a custom error that I'll raise in this case, so users can catch this error specifically !
I'll update the issue when it's done :) I'm a lil busy right now but I'm doing my best
Are you ok with these changes ? https://github.com/mxrch/ProtoDeep/commit/fe01ca393d5606dcc60fddf3ba4f723110173408
If you want to thrown an exception in that function if it cannot decode it, that seems like a sensible approach,
however the exception being thrown right now is simply the result of a logic error, so I don't think catching any exception and replacing it with a ProtoDeepCannotDecode
exception is the best approach.
This line:
https://github.com/mxrch/ProtoDeep/blob/e5206804c2faac86fe06707bec1781dfdfbc0f22/protodeep/lib.py#L168
Is trying to index None
(returned by find_proto_schema if it cannot decode it),
so maybe that would be the correct place to raise the error?