{"record":{"id":"5051b90e90f1da33","repo":"astral-sh/ruff","slug":"json-parsing-failure-json-err-5051b9","errorCode":null,"errorMessage":"JSON parsing failure:\n{json_err}","messagePattern":"JSON parsing failure:\n(.+?)","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/ty_server/src/server/api.rs","lineNumber":495,"sourceCode":"/// Tries to cast a serialized request from the server into\n/// a parameter type for a specific request handler.\n/// It is *highly* recommended to not override this function in your\n/// implementation.\nfn cast_request<Req>(\n    request: server::Request,\n) -> Result<(\n    RequestId,\n    <<Req as RequestHandler>::RequestType as Request>::Params,\n)>\nwhere\n    Req: RequestHandler,\n    <<Req as RequestHandler>::RequestType as Request>::Params: UnwindSafe,\n{\n    request\n        .extract(Req::METHOD.as_str())\n        .map_err(|err| match err {\n            json_err @ server::ExtractError::JsonError { .. } => {\n                anyhow::anyhow!(\"JSON parsing failure:\\n{json_err}\")\n            }\n            server::ExtractError::MethodMismatch(_) => {\n                unreachable!(\n                    \"A method mismatch should not be possible here \\\n                    unless you've used a different handler (`Req`) \\\n                    than the one whose method name was matched against earlier.\"\n                )\n            }\n        })\n        .with_failure_code(server::ErrorCode::InvalidParams)\n}\n\n/// Sends back a response to the client, but only if the request wasn't cancelled.\nfn respond<Req>(\n    id: &RequestId,\n    result: Result<<<Req as RequestHandler>::RequestType as Request>::Result>,\n    client: &Client,\n    log_guidance: &str,","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ty_server/src/server/api.rs#L477-L513","documentation":"`cast_request` deserializes the JSON `params` of an incoming LSP request into the typed parameter struct for a specific request handler. When serde fails to parse the JSON into `Req::Params` (an `ExtractError::JsonError`), the server returns this error with code InvalidParams (-32602). It means the client sent params that do not match the LSP schema for that method.","triggerScenarios":"The LSP client sends a request whose `params` field is missing, has the wrong shape (e.g. a string where an object is expected), or contains values of unexpected types, and the server extracts them via `request.extract::<Req>()`.","commonSituations":"A client or plugin speaking a slightly different LSP version than ty expects; a custom/bridging client (Emacs lsp-mode, Neovim, custom scripts) hand-crafting JSON-RPC requests; version skew after ty added a new field to a request's params.","solutions":["Log the raw JSON `params` of the failing request and compare it with the LSP spec / ty's expected params type for that method","Update the LSP client (or its ty extension) so it serializes params matching the current LSP schema","If hand-crafting requests, wrap params in the exact object shape the method requires (e.g. `{\"textDocument\": {\"uri\": ...}, \"position\": {\"line\": ..., \"character\": ...}}`)","Check for ty/client version mismatch and pin compatible versions"],"exampleFix":"// before (hand-crafted hover request)\n{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"textDocument/hover\",\"params\":{\"uri\":\"file:///a.py\",\"position\":[3, 7]}}\n// after\n{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"textDocument/hover\",\"params\":{\"textDocument\":{\"uri\":\"file:///a.py\"},\"position\":{\"line\":3,\"character\":7}}}","handlingStrategy":"validation","validationCode":"// Validate a hover request payload before sending\nfunction validHoverParams(p) {\n  return p && typeof p === 'object'\n    && p.textDocument && typeof p.textDocument.uri === 'string'\n    && p.position && Number.isInteger(p.position.line)\n    && Number.isInteger(p.position.character);\n}\nif (!validHoverParams(params)) throw new Error('invalid LSP hover params');\nsendRequest('textDocument/hover', params);","typeGuard":"function isPosition(p) {\n  return typeof p === 'object' && p !== null\n    && Number.isInteger(p.line) && p.line >= 0\n    && Number.isInteger(p.character) && p.character >= 0;\n}\nfunction isHoverParams(p) {\n  return typeof p === 'object' && p !== null\n    && typeof (p.textDocument && p.textDocument.uri) === 'string' && isPosition(p.position);\n}","tryCatchPattern":null,"preventionTips":["Use a maintained LSP client library (vscode-languageserver, lsp-types, lsp-mode) instead of hand-crafted JSON","Keep client and ty versions in sync with the LSP version each supports","Enable LSP trace logging to inspect exact params sent","Test protocol integrations against the LSP JSON schema"],"tags":["lsp","json","serialization","invalid-params"],"backgroundTag":"json-parsing-error","analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}