Skip to content

fix: ensure error and result are mutually exclusive in JSON-RPC responses (#766) - #768

Merged
randy3k merged 1 commit into
masterfrom
fix/jsonrpc-error-response
Sep 16, 2026
Merged

randy3k merged 1 commit into
masterfrom
fix/jsonrpc-error-response

Conversation

@randy3k

@randy3k randy3k commented Sep 15, 2026

Copy link
Copy Markdown
Member

Fixes #766

Summary

Per JSON-RPC 2.0 (Section 5):

Either the result member or error member MUST be included, but both members MUST NOT be included.

Previously, Response() unconditionally included result = self in the initial payload list(), so error responses produced both result: null and error: {...}, causing strict clients like Neovim's built-in vim.lsp to terminate the connection.

Changes

  • In R/protocol.R (Response()):
    • Construct payload with error when !is.null(self), and with result otherwise.
  • In tests/testthat/test-response-json.R:
    • Update expected payloads to reflect mutual exclusivity of result and error.
    • Assert that error responses do not contain result, and success responses (including those with result = NULL) do not contain error.

@renkun-ken renkun-ken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks!

@randy3k
randy3k merged commit c476788 into master Sep 16, 2026
5 checks passed
@randy3k
randy3k deleted the fix/jsonrpc-error-response branch September 16, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG REPORT]: Cancellation responses include both result:null and error, and violate JSON-RPC 2.0

2 participants