{"record":{"id":"43e0ee9481bf097e","repo":"BoundaryML/baml","slug":"client-closed","errorCode":null,"errorMessage":"Client closed","messagePattern":"Client closed","errorType":"error_code","errorClass":"LspError","httpStatus":null,"severity":"info","filePath":"baml_language/crates/baml_lsp/src/error.rs","lineNumber":22,"sourceCode":"\n/// Every failure a request or notification handler can report.\n///\n/// Serialized to the wire exclusively through [`LspError::to_response_error`];\n/// the legacy `-32001 UnknownErrorCode` is never emitted.\n#[derive(Debug, thiserror::Error)]\npub enum LspError {\n    #[error(\"{0}\")]\n    NotificationExtractError(lsp_server::ExtractError<lsp_server::Notification>),\n    #[error(\"Notification not supported: {0}\")]\n    NotificationNotSupported(String),\n    #[error(\"{0}\")]\n    RequestExtractError(lsp_server::ExtractError<lsp_server::Request>),\n    #[error(\"Request not supported: {0}\")]\n    RequestNotSupported(String),\n    #[error(\"Failed to serialize request result: {0}\")]\n    RequestSerializeError(serde_json::Error),\n    /// The client's sink is gone; nothing more can be delivered.\n    #[error(\"Client closed\")]\n    ClientClosed,\n    /// Bounded transport backpressure (LSP `RequestFailed`, `-32803`).\n    #[error(\"LSP outbound sink is saturated\")]\n    OutboundSaturated,\n    /// A frame larger than the transport limit (LSP `RequestFailed`,\n    /// `-32803`).\n    #[error(\"LSP outbound frame exceeds the transport limit\")]\n    OutboundOversized,\n    #[error(\"Invalid command arguments for command: {command}: {message}\")]\n    InvalidCommandArguments { command: String, message: String },\n    #[error(\"File not found: {}\", .0.display())]\n    FileNotFound(PathBuf),\n    #[error(\"Path is invalid: {}: {message}\", path.display())]\n    InvalidPath { path: PathBuf, message: String },\n    /// The document's path is under no known source root.\n    #[error(\"No source root contains {}\", .0.display())]\n    NoRootForPath(PathBuf),\n    /// Cancellation claimed the response while the request was queued or","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_lsp/src/error.rs#L4-L40","documentation":"LspError::ClientClosed signals that the client's outbound sink is gone, so the server can no longer deliver messages. thiserror renders the fixed message 'Client closed'. It is an expected lifecycle condition, not a bug in message handling.","triggerScenarios":"Writing a response or notification after the client disconnected / the connection loop ended; sending on a closed channel backing the LSP sink during shutdown.","commonSituations":"Editor closed or LSP client killed while a long-running request (formatting, diagnostics) is still in flight; slow handler finishing after shutdown; tests tearing down the transport early.","solutions":["Treat this as normal shutdown: cancel outstanding work and exit the handler loop","Check sink/connection liveness before dispatching long-running work","Log at info/debug level rather than surfacing it as a user-facing failure"],"exampleFix":"// before\nsend(response)?; // Err(ClientClosed) bubbles up\n// after\nif let Err(LspError::ClientClosed) = send(response) {\n    log::info!(\"client disconnected; dropping response\");\n    return Ok(());\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"fn is_client_closed(e: &LspError) -> bool {\n    matches!(e, LspError::ClientClosed)\n}","tryCatchPattern":"if let Err(LspError::ClientClosed) = sink.send(msg) {\n    log::info!(\"client gone; aborting send loop\");\n    return Ok(());\n}","preventionTips":["Track connection liveness and cancel background work on disconnect","Avoid spawning fire-and-forget sends that outlive the transport"],"tags":["lsp","connection","shutdown","rust"],"backgroundTag":"broken-pipe","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}