BoundaryML/baml · error · LspError
-32602
-32602
Error message
Invalid params: {0} What it means
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.
Source
Thrown at baml_language/crates/baml_lsp/src/error.rs:57
NoRootForPath(PathBuf),
/// Cancellation claimed the response while the request was queued or
/// running (LSP `RequestCanceled`, `-32800`).
#[error("Request canceled: {0}")]
RequestCanceled(String),
/// The request's snapshot became stale under an applied source change
/// (LSP `ContentModified`, `-32801`).
#[error("Content modified: {0}")]
ContentModified(String),
/// A valid request that cannot be served right now (LSP `RequestFailed`,
/// `-32803`).
#[error("{0}")]
RequestFailed(String),
/// Violated invariants, panics, serialization (LSP `InternalError`,
/// `-32603`).
#[error("Internal error: {0}")]
Internal(String),
/// Malformed params, position, or range (LSP `InvalidParams`, `-32602`).
#[error("Invalid params: {0}")]
InvalidParams(String),
/// A request before `initialize` completed (LSP `ServerNotInitialized`,
/// `-32002`).
#[error("Server not initialized: {0}")]
ServerNotInitialized(String),
}
impl LspError {
/// The one LSP error-code mapping.
#[must_use]
pub fn to_response_error(&self) -> lsp_server::ResponseError {
use lsp_server::ErrorCode;
let code = match self {
LspError::NotificationExtractError(_)
| LspError::RequestExtractError(_)
| LspError::InvalidCommandArguments { .. }
| LspError::InvalidParams(_) => ErrorCode::InvalidParams,
LspError::NotificationNotSupported(_) | LspError::RequestNotSupported(_) => {View on GitHub (pinned to bd85ce9dee)
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.
Example fix
// before
const params = { position: { line: 1, character: 0 } }; // 1-based guess
// after
const params = { position: { line: 0, character: 0 } }; // LSP positions are 0-based Defensive patterns
Strategy: validation
Validate before calling
function inBounds(position, docLines) {
return position.line >= 0 && position.line < docLines.length &&
position.character >= 0 && position.character <= docLines[position.line].length;
} Type guard
function isValidPosition(p) {
return p != null && Number.isInteger(p.line) && p.line >= 0 &&
Number.isInteger(p.character) && p.character >= 0;
} Try / catch
try {
return await request('textDocument/hover', { textDocument, position });
} catch (e) {
if (e.code === -32602 || /Invalid params:/.test(e.message ?? '')) {
console.warn('Bad params for hover:', { textDocument, position });
return null;
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- {0}
- Invalid command arguments for command: {command}: {message}
- Path is invalid: {}: {message}
- -32800
- -32002
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/56f117678a261d37.
Report an issue: GitHub.