json-rpc icon indicating copy to clipboard operation
json-rpc copied to clipboard

JSONRPCResponseManager.handle silences the exception if "id" is not passed

Open faerot opened this issue 3 years ago • 0 comments

Description

There is no way to handle exceptions if request does not pass "id" attribute. JSONRPCResponseManager.handle() should always return a response with an error in case of exception in user code or if it is not possible, there should be an argument to enable this (strict) behavior.

Steps to Reproduce

Run this code:

import jsonrpc

dispatcher = jsonrpc.Dispatcher()

@dispatcher.add_method
def test():
    1/0

request = '{"jsonrpc": "2.0", "method": "test", "params": []}'

print(jsonrpc.JSONRPCResponseManager.handle(request, dispatcher))

Expected behavior: error response should be printed

Actual behavior: None is printed

Reproduces how often: always

Versions

all

Additional Information

If you change request to '{"jsonrpc": "2.0", "method": "test", "params": [], "id": 1}' it expectedly returns response with an error:

{'jsonrpc': '2.0', 'id': 1, 'error': {'message': 'Server error', 'code': -32000, 'data': {'message': 'integer division or modulo by zero', 'args': ('integer division or modulo by zero',), 'type': 'ZeroDivisionError'}}}

faerot avatar Sep 21 '22 15:09 faerot