From cb3d54929d3d0f72924e645c99d7c0ca48840255 Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Mon, 3 Apr 2023 19:23:07 +0200 Subject: [PATCH] Fix exception for null response id --- plugin/core/sessions.py | 5 ++++- plugin/core/windows.py | 8 ++++---- tests/test_session.py | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index b065c6bcc..48f348876 100644 --- a/plugin/core/sessions.py +++ b/plugin/core/sessions.py @@ -1105,7 +1105,7 @@ def outgoing_notification(self, method: str, params: Any) -> None: pass @abstractmethod - def incoming_response(self, request_id: int, params: Any, is_error: bool) -> None: + def incoming_response(self, request_id: Optional[int], params: Any, is_error: bool) -> None: pass @abstractmethod @@ -2079,6 +2079,9 @@ def deduce_payload( self._logger.incoming_notification(method, result, res[0] is None) return res elif "id" in payload: + if payload["id"] is None: + self._logger.incoming_response(None, payload.get("error"), True) + return (None, None, None, None, None) response_id = int(payload["id"]) handler, method, result, is_error = self.response_handler(response_id, payload) self._logger.incoming_response(response_id, result, is_error) diff --git a/plugin/core/windows.py b/plugin/core/windows.py index 986e8b079..306690e9c 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -548,7 +548,7 @@ def __init__(self) -> None: def start_tracking(self, request_id: int) -> None: self._start_times[request_id] = perf_counter() - def end_tracking(self, request_id) -> str: + def end_tracking(self, request_id: int) -> str: duration = '-' if request_id in self._start_times: start = self._start_times.pop(request_id) @@ -613,11 +613,11 @@ def outgoing_notification(self, method: str, params: Any) -> None: return self.log(self._format_notification(" ->", method), params) - def incoming_response(self, request_id: int, params: Any, is_error: bool) -> None: + def incoming_response(self, request_id: Optional[int], params: Any, is_error: bool) -> None: if not userprefs().log_server: return direction = "<~~" if is_error else "<<<" - duration = self._request_time_tracker.end_tracking(request_id) + duration = self._request_time_tracker.end_tracking(request_id) if request_id is not None else "-" self.log(self._format_response(direction, request_id, duration), params) def incoming_request(self, request_id: Any, method: str, params: Any) -> None: @@ -717,7 +717,7 @@ def outgoing_request(self, request_id: int, method: str, params: Any) -> None: 'direction': self.DIRECTION_OUTGOING, }) - def incoming_response(self, request_id: int, params: Any, is_error: bool) -> None: + def incoming_response(self, request_id: Optional[int], params: Any, is_error: bool) -> None: self._broadcast_json({ 'server': self._server_name, 'id': request_id, diff --git a/tests/test_session.py b/tests/test_session.py index 615f71546..b6a82d61e 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -61,7 +61,7 @@ def outgoing_request(self, request_id: int, method: str, params: Any, blocking: def outgoing_notification(self, method: str, params: Any) -> None: pass - def incoming_response(self, request_id: int, params: Any, is_error: bool, blocking: bool) -> None: + def incoming_response(self, request_id: Optional[int], params: Any, is_error: bool, blocking: bool) -> None: pass def incoming_request(self, request_id: Any, method: str, params: Any) -> None: