{"record":{"id":"56f117678a261d37","repo":"BoundaryML/baml","slug":"32602-invalid-params-0","errorCode":"-32602","errorMessage":"Invalid params: {0}","messagePattern":"Invalid params: (.+?)","errorType":"error_code","errorClass":"LspError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_lsp/src/error.rs","lineNumber":57,"sourceCode":"    NoRootForPath(PathBuf),\n    /// Cancellation claimed the response while the request was queued or\n    /// running (LSP `RequestCanceled`, `-32800`).\n    #[error(\"Request canceled: {0}\")]\n    RequestCanceled(String),\n    /// The request's snapshot became stale under an applied source change\n    /// (LSP `ContentModified`, `-32801`).\n    #[error(\"Content modified: {0}\")]\n    ContentModified(String),\n    /// A valid request that cannot be served right now (LSP `RequestFailed`,\n    /// `-32803`).\n    #[error(\"{0}\")]\n    RequestFailed(String),\n    /// Violated invariants, panics, serialization (LSP `InternalError`,\n    /// `-32603`).\n    #[error(\"Internal error: {0}\")]\n    Internal(String),\n    /// Malformed params, position, or range (LSP `InvalidParams`, `-32602`).\n    #[error(\"Invalid params: {0}\")]\n    InvalidParams(String),\n    /// A request before `initialize` completed (LSP `ServerNotInitialized`,\n    /// `-32002`).\n    #[error(\"Server not initialized: {0}\")]\n    ServerNotInitialized(String),\n}\n\nimpl LspError {\n    /// The one LSP error-code mapping.\n    #[must_use]\n    pub fn to_response_error(&self) -> lsp_server::ResponseError {\n        use lsp_server::ErrorCode;\n        let code = match self {\n            LspError::NotificationExtractError(_)\n            | LspError::RequestExtractError(_)\n            | LspError::InvalidCommandArguments { .. }\n            | LspError::InvalidParams(_) => ErrorCode::InvalidParams,\n            LspError::NotificationNotSupported(_) | LspError::RequestNotSupported(_) => {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_lsp/src/error.rs#L39-L75","documentation":"LspError::InvalidParams is returned when a request's parameters are malformed: a bad position, an out-of-range range, or any param that fails structural validation. It maps to the LSP InvalidParams code -32602 and prefixes the payload with 'Invalid params:'. It is distinct from InvalidCommandArguments, which covers executeCommand payloads specifically.","triggerScenarios":"A textDocument position request sent with line/character beyond the document's bounds; missing required fields in request params; params that fail JSON deserialization into the request's expected type.","commonSituations":"Clients using stale document contents to compute positions after an edit; 0-based vs 1-based line/character confusion in custom tooling; null or undefined fields passed where structured values are required.","solutions":["Clamp/validate positions against the current document version's line count and line lengths before sending.","Ensure LSP positions are 0-based (line 0, character 0 is the first character of the file).","Re-read the latest document version from the client before computing positions or ranges.","Validate request params against the LSP schema for the method being called."],"exampleFix":"// before\nconst params = { position: { line: 1, character: 0 } }; // 1-based guess\n// after\nconst params = { position: { line: 0, character: 0 } }; // LSP positions are 0-based","handlingStrategy":"validation","validationCode":"function inBounds(position, docLines) {\n  return position.line >= 0 && position.line < docLines.length &&\n    position.character >= 0 && position.character <= docLines[position.line].length;\n}","typeGuard":"function isValidPosition(p) {\n  return p != null && Number.isInteger(p.line) && p.line >= 0 &&\n    Number.isInteger(p.character) && p.character >= 0;\n}","tryCatchPattern":"try {\n  return await request('textDocument/hover', { textDocument, position });\n} catch (e) {\n  if (e.code === -32602 || /Invalid params:/.test(e.message ?? '')) {\n    console.warn('Bad params for hover:', { textDocument, position });\n    return null;\n  }\n  throw e;\n}","preventionTips":["Remember LSP positions are 0-based line and character","Recompute positions from the latest document version after every edit","Validate params structurally against the LSP method schema before sending"],"tags":["lsp","params","validation","json-rpc"],"backgroundTag":"invalid-argument-value","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}