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 for null response id #2233

Merged
merged 1 commit into from
Apr 9, 2023
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
5 changes: 4 additions & 1 deletion plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions plugin/core/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down