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

guess_schema throwing exception #4

Open
learn-more opened this issue Mar 19, 2023 · 4 comments
Open

guess_schema throwing exception #4

learn-more opened this issue Mar 19, 2023 · 4 comments

Comments

@learn-more
Copy link
Contributor

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)
@mxrch
Copy link
Owner

mxrch commented Mar 19, 2023

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 !

@mxrch
Copy link
Owner

mxrch commented Mar 19, 2023

I'll update the issue when it's done :)
I'm a lil busy right now but I'm doing my best

@mxrch
Copy link
Owner

mxrch commented Mar 19, 2023

Are you ok with these changes ? fe01ca3

@learn-more
Copy link
Contributor Author

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:

parsed = schema[0]

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants