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

Fix exception processing #15

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
### direnv ###
.direnv
.envrc

### VisualStudioCode ###
.vscode/*
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
python-mqttrpc (1.2.5) stable; urgency=medium

* Fix exception processing

-- Petr Krasnoshchekov <petr.krasnoshchekov@wirenboard.com> Tue, 23 Jul 2024 12:49:49 +0500

python-mqttrpc (1.2.4) stable; urgency=medium

* mqtt-rpc-client: fix error handling
Expand Down
1 change: 0 additions & 1 deletion debian/source/format

This file was deleted.

2 changes: 1 addition & 1 deletion mqttrpc/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
For usage examples see :meth:`Dispatcher.add_method`

"""

from collections.abc import MutableMapping


class Dispatcher(MutableMapping):

"""Dictionary like object which maps method_name to method."""

def __init__(self, prototype=None):
Expand Down
7 changes: 3 additions & 4 deletions mqttrpc/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@


class MQTTRPCResponseManager(object):

"""MQTT-RPC response manager.

Method brings syntactic sugar into library. Given dispatcher it handles
Expand Down Expand Up @@ -56,7 +55,7 @@ def handle(cls, request_str, service_id, method_id, dispatcher):
return erroneous_response

@classmethod
def _process_exception(cls, request, e):
def _process_exception(cls, request, method, e):
data = {
"type": e.__class__.__name__,
"args": e.args,
Expand Down Expand Up @@ -91,7 +90,7 @@ def handle_request(cls, request, service_id, method_id, dispatcher):
try:
result = method(*request.args, **request.kwargs)
except Exception as e:
output = cls._process_exception(request, e)
output = cls._process_exception(request, method, e)
else:
output = MQTTRPC10Response(_id=request._id, result=result)
finally:
Expand Down Expand Up @@ -124,7 +123,7 @@ async def handle_request(cls, request, service_id, method_id, dispatcher):
try:
result = await method(*request.args, **request.kwargs)
except Exception as e:
output = cls._process_exception(request, e)
output = cls._process_exception(request, method, e)
else:
output = MQTTRPC10Response(_id=request._id, result=result)
finally:
Expand Down
4 changes: 0 additions & 4 deletions mqttrpc/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class MQTTRPCBaseRequest(JSONSerializable):

"""Base class for JSON-RPC 1.0 and JSON-RPC 2.0 requests."""

def __init__(self, params=None, _id=None, is_notification=None):
Expand Down Expand Up @@ -50,7 +49,6 @@ def json(self):


class MQTTRPCBaseResponse(JSONSerializable):

"""Base class for JSON-RPC 1.0 and JSON-RPC 2.0 responses."""

def __init__(self, result=None, error=None, _id=None):
Expand Down Expand Up @@ -80,7 +78,6 @@ def json(self):


class MQTTRPC10Request(MQTTRPCBaseRequest):

"""A rpc call is represented by sending a Request object to a Server.

:param params: A Structured value that holds the parameter values to be
Expand Down Expand Up @@ -181,7 +178,6 @@ def from_json(cls, json_str):


class MQTTRPC10Response(MQTTRPCBaseResponse):

"""JSON-RPC response object to JSONRPC20Request.

When a rpc call is made, the Server MUST reply with a Response, except for
Expand Down