{"record":{"id":"171949bdde621536","repo":"BoundaryML/baml","slug":"internalerror-failed-to-serialize-functions","errorCode":"InternalError","errorMessage":"Failed to serialize functions: {:?}","messagePattern":"Failed to serialize functions: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_server/src/server/api.rs","lineNumber":117,"sourceCode":"                            .iter()\n                            .map(|f| BamlFunctionResult {\n                                name: f.name.clone(),\n                                span: BamlFunctionSpan {\n                                    file_path: f.span.file_path.clone(),\n                                    start: f.span.start,\n                                    end: f.span.end,\n                                },\n                            })\n                            .collect::<Vec<BamlFunctionResult>>();\n\n                        all_functions.extend(functions);\n                    }\n\n                    let result = serde_json::to_value(all_functions);\n                    if let Ok(result) = result {\n                        Ok((result,))\n                    } else {\n                        Err(anyhow::anyhow!(\n                            \"Failed to serialize functions: {:?}\",\n                            result\n                        ))\n                    }\n                };\n                if let Ok((result,)) = result {\n                    responder.respond(id, Ok(result)).unwrap();\n                } else {\n                    // no action\n                    // responder.respond(id, Err(result.unwrap_err())).unwrap();\n                }\n            });\n        }\n        \"requestDiagnostics\" => {\n            // tracing::info!(\"---- requestDiagnostics\");\n            return Task::local(move |session, notifier, _requester, responder| {\n                let result: anyhow::Result<()> = (|| {\n                    // tracing::info!(\"requestDiagnostics: {:?}\", req.params);","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_server/src/server/api.rs#L99-L135","documentation":"The language server's internal API endpoint that lists all functions fails when serde_json cannot serialize the collected all_functions value into JSON. Serialization is essentially infallible for normal data, so this usually indicates a non-serializable type (e.g. a map with non-string keys) sneaking into the value.","triggerScenarios":"The api.rs request handler builds all_functions and calls serde_json::to_value, which returns Err — typically because a function entry contains a non-JSON-serializable structure (non-string map keys, NaN in floats, etc.).","commonSituations":"Custom or newly added function metadata with exotic types breaking serde's JSON model; concurrent schema changes between collection and serialization; rarely, extremely large payloads causing serializer limits.","solutions":["Inspect all_functions for values not representable in JSON (non-string keys, unsupported numeric types) and convert them to strings.","Include the serde error in the message (currently the Err value is logged, not the cause) to diagnose.","Derive Serialize consistently on all function metadata types.","Map the failure to a proper JSON-RPC internal error response instead of a bare anyhow error."],"exampleFix":"// before\nErr(anyhow::anyhow!(\"Failed to serialize functions: {:?}\", result))\n// after\nErr(anyhow::anyhow!(\"Failed to serialize functions: {:?}\", result.err()))","handlingStrategy":"fallback","validationCode":"const kind = getSymbolKindAt(uri, position);\nif (!['class','enum','typeAlias'].includes(kind)) return;","typeGuard":"const isRenamableSymbol = (k: string | undefined): k is 'class'|'enum'|'typeAlias' =>\n  k === 'class' || k === 'enum' || k === 'typeAlias';","tryCatchPattern":"try {\n  await renameSymbol(uri, position, newName);\n} catch (e) {\n  if (String(e.message).startsWith('Cannot rename symbol')) {\n    notifyUser('Only classes, enums, and type aliases can be renamed');\n  }\n}","preventionTips":["Place the cursor precisely on the identifier of a class/enum/type alias.","Fix compile errors so symbols resolve in the runtime.","Avoid renaming client/test/field identifiers via LSP rename.","Improve server error codes for unsupported symbol kinds."],"tags":["serde","json","serialization"],"backgroundTag":"json-serialization-failed","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"}