Comments (8)
@deadbeef404 sure, let me see. I agree, TypeError inside the method would throw 'Invalid params' exception.
from json-rpc.
@deadbeef404 let us solve this issue from the business side.
Technically, it is impossible to distinguish TypeError
because of invalid parameters and TypeError
thrown from the function itself. Unfortunately, json-rpc could not do much about it, it does not know function it calls. What is possible to do:
- Catch TypeError from inside the function and throw JSONRPCDispatchException
https://github.com/pavlov99/json-rpc/blob/master/jsonrpc/exceptions.py#L172
From library side, need to document it better. - I could add more information to error's data field, as implemented for general exceptions: https://github.com/pavlov99/json-rpc/blob/master/jsonrpc/manager.py#L109-114
Would it solve your issue? - Use
*args
,**kwargs
for functions and accepts/returns decorators https://wiki.python.org/moin/PythonDecoratorLibrary#Type_Enforcement_.28accepts.2Freturns.29
But this is the least desirable way.
Let me know what do you think about it.
from json-rpc.
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
from json-rpc.
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 *request.args, **request.kwargs
.
Taking this into account, the most ideal way would be to actually perform some type of argument matching by accessing method.func_code.co_varnames
to inspect the call before it happens. Actually, this argument matching approach, if implemented, would best be run after the TypeError occurs, that way the code would not add the upfront overhead on every call, just those that have a TypeError already occurring.
Have you considered this approach?
from json-rpc.
For a better approach than the simple co_varnames, this seems useful: http://stackoverflow.com/a/197053/945856
from json-rpc.
@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.
from json-rpc.
@deadbeef404 , updated code https://github.com/pavlov99/json-rpc/blob/master/jsonrpc/manager.py#L117-120
Version 1.9.0 has been released.
from json-rpc.
Thank you for your hard work! đ
from json-rpc.
Related Issues (20)
- Consider switching to CircleCI HOT 1
- pip install json-rpc breaks pyls installation HOT 3
- Django documentation params HOT 8
- json-rpc 1.0 requires 'result' and 'error' attributes in the HTTP responses
- Cors Header Missing ? HOT 1
- Feature proposal: Remote Method Invocation dispatcher HOT 1
- Can't an AsyncJSONRPCResponseManager be added? HOT 4
- Need a way to intercept exception to send http 401
- Unreachable OpenRPC rpc.discover method HOT 1
- ĺ źĺŽš django 4.0 HOT 2
- JSONRPCResponseManager.handle silences the exception if "id" is not passed
- Missing git tags for 1.14.0 and 1.15.0 releases
- Add names for django's views HOT 3
- License file in pypi archive HOT 5
- Link to implementations on project page is useless
- Uart as a transport layer HOT 1
- Server issued notifications HOT 2
- Using SELF in class methods when using JSON-RPC as a class HOT 2
- `make env` fails without requirements-dev.txt HOT 1
- How to deploy on production server? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ď¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-rpc.