{"record":{"id":"89ea25a805ca69e6","repo":"rust-lang/rust-analyzer","slug":"unable-to-serialize-data","errorCode":null,"errorMessage":"Unable to serialize data","messagePattern":"Unable to serialize data","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rust-analyzer/src/tracing/json.rs","lineNumber":70,"sourceCode":"        span.extensions_mut().insert(data);\n    }\n\n    fn on_event(&self, _event: &Event<'_>, _ctx: Context<'_, S>) {}\n\n    fn on_close(&self, id: Id, ctx: Context<'_, S>) {\n        #[derive(serde_derive::Serialize)]\n        struct JsonDataInner {\n            name: &'static str,\n            elapsed_ms: u128,\n        }\n\n        let span = ctx.span(&id).unwrap();\n        let Some(data) = span.extensions_mut().remove::<JsonData>() else {\n            return;\n        };\n\n        let data = JsonDataInner { name: data.name, elapsed_ms: data.start.elapsed().as_millis() };\n        let mut out = serde_json::to_string(&data).expect(\"Unable to serialize data\");\n        out.push('\\n');\n        self.writer.make_writer().write_all(out.as_bytes()).expect(\"Unable to write data\");\n    }\n}\n\n#[derive(Default, Clone, Debug)]\npub(crate) struct JsonFilter {\n    pub(crate) allowed_names: Option<FxHashSet<String>>,\n}\n\nimpl JsonFilter {\n    pub(crate) fn from_spec(spec: &str) -> Self {\n        let allowed_names = if spec == \"*\" {\n            None\n        } else {\n            Some(FxHashSet::from_iter(spec.split('|').map(String::from)))\n        };\n","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/rust-analyzer/src/tracing/json.rs#L52-L88","documentation":"In the JSON profiling layer's on_close, span timing data is serialized with serde_json before being appended to the output writer. serde_json::to_string on a struct of a string name plus an integer elapsed_ms cannot realistically fail, so expect is used as a sanity check; a panic here would indicate corrupted extensions data or serde internals.","triggerScenarios":"Essentially only if JsonData stored in the tracing span extensions was constructed with a name that cannot serialize (practically impossible with a String) or a serde/alloc failure; hit when a profiled span closes while the JSON profiler layer is active.","commonSituations":"Developers rarely hit this; it may surface when patching the profiler to add new fields to JsonDataInner that are not serializable (e.g. non-string keys in maps, inf/nan floats).","solutions":["Check any local modifications to JsonDataInner for fields serde cannot serialize (NaN floats, non-string map keys).","Switch to serde_json::to_string(&data).unwrap_or_default() or log-and-continue if you extend the payload.","Update/verify serde_json version in the lockfile for known regressions."],"exampleFix":"// before\nlet mut out = serde_json::to_string(&data).expect(\"Unable to serialize data\");\n// after\nlet mut out = serde_json::to_string(&data)\n    .unwrap_or_else(|e| format!(\"{{\\\"name\\\":\\\"serialize-error\\\",\\\"elapsed_ms\\\":-1}}\", )); let _ = e;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match serde_json::to_string(&data) {\n    Ok(mut out) => { out.push('\\n'); ... }\n    Err(e) => eprintln!(\"profile serialization failed: {e}\"),\n}","preventionTips":["Keep JsonDataInner fields plain serializable types (String, integers)","Avoid adding floats that can be NaN to the payload","Add tests when extending profiler payloads"],"tags":["rust-analyzer","tracing","serialization","panic"],"backgroundTag":"serde-serialization-panic","analyzedSha":"e8f7e90aa3e7b26aa9a000200f606c1078da99ec","analyzedAt":"2026-09-03T21:08:06.959Z","contentChangedAt":"2026-09-03T21:08:06.959Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}