-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
TypeError in user code is hidden by library #25
Comments
@deadbeef404 sure, let me see. I agree, TypeError inside the method would throw 'Invalid params' exception. |
@deadbeef404 let us solve this issue from the business side.
Let me know what do you think about it. |
I have implemented body message to TypeError (InvalidParams). https://github.com/pavlov99/json-rpc/blob/master/jsonrpc/manager.py#L106-110 It gives more information about the error: https://github.com/pavlov99/json-rpc/blob/master/jsonrpc/tests/test_manager.py#L82-91 Versionadded: 1.8.4 |
This change is in improvement as it would at lease preserve some information. There is the slight issue though: this is still is returning the wrong error code for the exception, and thus not matching the specification. In regards to your point "it does not know what function it calls", well, it does. It has a reference to it to which it passes Taking this into account, the most ideal way would be to actually perform some type of argument matching by accessing |
For a better approach than the simple co_varnames, this seems useful: http://stackoverflow.com/a/197053/945856 |
@deadbeef404 point taken. I did not want to play with code inspection, but seems we could not avoid it. To follow specification is important and I agree with you that current error type is not correct in case of TypeError inside the function. Let me play with the code and add suggested functionality. |
@deadbeef404 , updated code https://github.com/pavlov99/json-rpc/blob/master/jsonrpc/manager.py#L117-120 |
Thank you for your hard work! 👍 |
Can I please draw your attention to
jsonrpc/manager.py
in__get_responses
where parameters are validated for a method.Due to the way that parameters are validated, a
TypeError
is raised when the method is given incorrect parameters, and thus, the following line is executedThe exception handling around this doesn't account for the fact that a developer's code within that method can potentially throw a
TypeError
. In this case, the real issue is hidden and the following error is returned:I've just lost some time investigating why I was getting this error, and it would be great to avoid inflicting that upon someone else.
The text was updated successfully, but these errors were encountered: