Skip to content

fix(json-rpc): use -32600 for valid-JSON non-object bodies#1483

Merged
pi0 merged 1 commit into
mainfrom
fix/json-rpc-err
Jul 18, 2026
Merged

fix(json-rpc): use -32600 for valid-JSON non-object bodies#1483
pi0 merged 1 commit into
mainfrom
fix/json-rpc-err

Conversation

@pi0x

@pi0x pi0x commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Closes #1480

processJsonRpcBody() returned -32700 Parse error for any body that was not an object, but by that point JSON.parse had already succeeded. Per JSON-RPC 2.0 §5.1, -32700 is reserved for "Invalid JSON was received by the server"; a body of 123, "str", true or null is well-formed JSON that simply is not a valid Request object, which is -32600 Invalid Request.

Truly malformed JSON still returns -32700 — that path is the catch around req.json() / message.json() and is untouched.

Regression tests added on both the HTTP and WebSocket handlers; both fail before the change (6 failures) and pass after.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Valid JSON values that aren’t objects or arrays now return the correct JSON-RPC “Invalid Request” error instead of “Parse error.”
    • Improved consistency across HTTP and WebSocket request handling, including strings, numbers, booleans, and null.
  • Tests
    • Added coverage for multiple non-object JSON request bodies.

Per JSON-RPC 2.0 §5.1, `-32700 Parse error` is reserved for "Invalid JSON
was received by the server". A body of `123`, `"str"`, `true` or `null` is
well-formed JSON — parsing succeeded — but is not a valid Request object,
so it must be `-32600 Invalid Request`.

Closes #1480

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@pi0x
pi0x requested a review from pi0 as a code owner July 18, 2026 07:59
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2443f1fb-0d7a-4d96-ba14-f5a898c53074

📥 Commits

Reviewing files that changed from the base of the PR and between 75ac47d and ab94cee.

📒 Files selected for processing (3)
  • src/utils/json-rpc.ts
  • test/json-rpc-ws.test.ts
  • test/json-rpc.test.ts

📝 Walkthrough

Walkthrough

Valid JSON primitive bodies are now classified as JSON-RPC Invalid Request errors, with parameterized HTTP and WebSocket tests covering strings, numbers, booleans, and null.

Changes

JSON-RPC validation

Layer / File(s) Summary
Primitive body classification and coverage
src/utils/json-rpc.ts, test/json-rpc.test.ts, test/json-rpc-ws.test.ts
processJsonRpcBody returns -32600 Invalid Request for parsed primitive bodies, with HTTP and WebSocket tests asserting the response shape and error details.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • h3js/h3#1180: Updates the same JSON-RPC body parsing and validation behavior.

Suggested labels: enhancement

Suggested reviewers: pi0

Poem

I’m a rabbit with packets to parse,
Valid JSON now follows its right course.
A string, a null, or a number in flight
Gets “Invalid Request” classified just right.
Hop hop—the tests keep watch!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main JSON-RPC fix for valid JSON primitive bodies.
Linked Issues check ✅ Passed The changes match the linked issue by returning -32600 for valid JSON primitives and keeping malformed JSON as -32700.
Out of Scope Changes check ✅ Passed The PR stays focused on the JSON-RPC error classification fix and related regression tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/json-rpc-err

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pi0
pi0 merged commit 5d0194a into main Jul 18, 2026
9 checks passed
@pi0
pi0 deleted the fix/json-rpc-err branch July 18, 2026 08:04
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.

JSON-RPC: valid-JSON primitive bodies return -32700 Parse error instead of -32600 Invalid Request

2 participants