{"record":{"id":"a5c30bf7a7607bd2","repo":"BoundaryML/baml","slug":"32002-server-not-initialized-0","errorCode":"-32002","errorMessage":"Server not initialized: {0}","messagePattern":"Server not initialized: (.+?)","errorType":"error_code","errorClass":"LspError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_lsp/src/error.rs","lineNumber":61,"sourceCode":"    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(_) => {\n                ErrorCode::MethodNotFound\n            }\n            LspError::ServerNotInitialized(_) => ErrorCode::ServerNotInitialized,\n            LspError::RequestCanceled(_) => ErrorCode::RequestCanceled,","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_lsp/src/error.rs#L43-L79","documentation":"LspError::ServerNotInitialized is returned when a request arrives before the initialize handshake has completed. Per the LSP specification, only 'initialize' and 'exit' (plus trivial notifications) are legal in this state; anything else is rejected with code -32002 and a message prefixed 'Server not initialized:'. The server throws this to enforce the mandated startup ordering.","triggerScenarios":"Client sends textDocument/*, workspace/*, or other requests before receiving the initialize response; the initialize response is lost or the client ignores it; a reconnecting client resumes requests without re-running initialize.","commonSituations":"Custom LSP clients that fire requests immediately after spawning the server process; race between editor startup and server readiness; a crashed initialize handshake leaving the server waiting.","solutions":["Await the successful response to the initialize request before sending any other requests.","Send the initialized notification after initialize completes, then begin normal requests.","Queue requests client-side until initialization finishes instead of firing them at startup.","If using a framework, ensure its LSP client lifecycle (initialize -> initialized -> ready) is respected."],"exampleFix":"// before\nspawnServer();\nrequest('textDocument/hover', params); // too early\n// after\nawait request('initialize', { capabilities: clientCapabilities });\nnotify('initialized', {});\nrequest('textDocument/hover', params);","handlingStrategy":"try-catch","validationCode":"let initialized = false;\nfunction assertReady() {\n  if (!initialized) throw new Error('LSP client not yet initialized');\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await request(method, params);\n} catch (e) {\n  if (e.code === -32002 || /Server not initialized:/.test(e.message ?? '')) {\n    await initializeAndReady();\n    return request(method, params); // retry once initialized\n  }\n  throw e;\n}","preventionTips":["Always await the initialize response before any other requests","Send the initialized notification before starting analysis traffic","Queue early requests client-side and flush them after the ready signal"],"tags":["lsp","initialization","lifecycle","json-rpc"],"backgroundTag":"server-not-initialized","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"}