Skip to content

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

Description

@pi0x

Minor JSON-RPC 2.0 spec deviation found during a pre-stable validation pass, verified against current main (75ac47d).

src/utils/json-rpc.ts:208-210:

// Body must be a non-null object or array.
if (!body || typeof body !== "object") {
  return createJsonRpcError(null, PARSE_ERROR, "Parse error");
}

A body of 123, "str", true, or null is well-formed JSON — parsing succeeded — but is not a valid Request object. Per JSON-RPC 2.0, -32700 Parse error is reserved for "Invalid JSON was received by the server"; a structurally invalid (non-object) request should be -32600 Invalid Request.

Verified: 123, "str", and null all currently return -32700 instead of -32600.

The surrounding handling is otherwise spec-correct (checked: []-32600, [1,2] → array of per-item -32600, notification suppression → 202 empty body, truly malformed JSON → -32700), so the fix is just distinguishing "JSON.parse failed" from "parsed but not an object" at this boundary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions