{"record":{"id":"b16b024050bbe2b1","repo":"BoundaryML/baml","slug":"failed-to-serialize-request-result-0","errorCode":null,"errorMessage":"Failed to serialize request result: {0}","messagePattern":"Failed to serialize request result: (.+?)","errorType":"exception","errorClass":"LspError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_lsp/src/error.rs","lineNumber":19,"sourceCode":"//! The one LSP error type and its JSON-RPC code table.\n\nuse std::path::PathBuf;\n\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.","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_lsp/src/error.rs#L1-L37","documentation":"LspError::RequestSerializeError occurs when the server cannot serialize a request's result value to JSON (serde_json::Error) before sending it back over the wire. thiserror formats it as 'Failed to serialize request result: {0}'.","triggerScenarios":"A handler returns a result value whose serde Serialize impl fails — e.g. NaN/f64 in a JSON position, non-string map keys, or a type missing Serialize derives — inside a response-building path.","commonSituations":"Adding a new LSP request handler and forgetting #[derive(Serialize)] on a nested type; returning f64::NAN from a hover position; serializing maps with non-string keys.","solutions":["Read the inner serde_json error to find the unserializable field","Ensure all response types (and nested types) derive or implement serde::Serialize","Sanitize f64 values (replace NaN/Infinity) before returning them as results"],"exampleFix":"// before\n#[derive(Debug)]\nstruct HoverData { value: f64 }\n// after\n#[derive(serde::Serialize)]\nstruct HoverData { #[serde(skip_serializing_if = \"f64::is_nan\")] value: f64 }","handlingStrategy":"validation","validationCode":"let json = serde_json::to_value(&result).map_err(|e| LspError::RequestSerializeError(e))?;","typeGuard":null,"tryCatchPattern":"match build_response() {\n    Err(LspError::RequestSerializeError(e)) => log::error!(\"unserializable result: {e}\"),\n    other => other?,\n}","preventionTips":["Derive Serialize on every type used in LSP responses, including nested ones","Never return NaN/Infinity in f64 fields of LSP responses","Unit-test serialization of every handler's result type"],"tags":["lsp","serialization","serde","rust"],"backgroundTag":"json-marshal-failed","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"}