{"record":{"id":"fa2c6a749f25a017","repo":"xai-org/grok-build","slug":"error-fa2c6a","errorCode":null,"errorMessage":"{}","messagePattern":"\\{\\}","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-hunk-tracker/src/loc/mod.rs","lineNumber":266,"sourceCode":"            let file = tokio::fs::OpenOptions::new()\n                .create(true)\n                .append(true)\n                .open(&self.path)\n                .await?;\n            self.file = Some(file);\n        }\n        // The `if` block above guarantees `self.file` is `Some` at this point.\n        Ok(self.file.as_mut().unwrap())\n    }\n}\n\nimpl HunkRecordWriter for JsonlHunkRecordWriter {\n    async fn write(&mut self, record: &HunkRecord) -> std::io::Result<()> {\n        use tokio::io::AsyncWriteExt;\n\n        let file = self.ensure_open().await?;\n        let mut line = serde_json::to_string(record)\n            .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;\n        line.push('\\n');\n        file.write_all(line.as_bytes()).await?;\n        Ok(())\n    }\n\n    async fn flush(&mut self) -> std::io::Result<()> {\n        use tokio::io::AsyncWriteExt;\n\n        if let Some(file) = self.file.as_mut() {\n            file.flush().await?;\n        }\n        Ok(())\n    }\n}\n\n// ---------------------------------------------------------------------------\n// LocAggregate (channel-based bridge to signals)\n// ---------------------------------------------------------------------------","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-hunk-tracker/src/loc/mod.rs#L248-L284","documentation":"JsonlHunkRecordWriter::write serializes each HunkRecord to JSON before appending a newline; if serde_json fails, the error is converted to io::ErrorKind::InvalidData. This is a programming/data error, not an I/O failure.","triggerScenarios":"Writing a HunkRecord whose fields cannot serialize to JSON (e.g. map keys that aren't strings, NaN in a float field when strict, or a custom Serialize impl that errors).","commonSituations":"Evolving HunkRecord with a non-JSON-safe field; passing records built from untrusted input with unexpected shapes; custom Serialize impls returning Err.","solutions":["Read the underlying serde_json error (the io error's source) to locate the failing field","Fix the offending field type or its Serialize implementation","Use serde_json::to_value in a debug assertion to fail fast at record construction"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"fn record_json_ok(r: &HunkRecord) -> bool {\n    serde_json::to_string(r).is_ok()\n}\ndebug_assert!(record_json_ok(record));","typeGuard":null,"tryCatchPattern":"if let Err(e) = writer.write(&record).await {\n    if e.kind() == std::io::ErrorKind::InvalidData {\n        eprintln!(\"record failed JSON serialization: {}\", e);\n    }\n    return Err(e.into());\n}","preventionTips":["Keep HunkRecord fields JSON-safe (no non-string map keys, no NaN)","Add a round-trip test serde_json::from_str::<HunkRecord>(&serde_json::to_string(&r)?)","Avoid custom Serialize impls that can return Err"],"tags":["io","serialization","json","rust","async"],"backgroundTag":"json-serialization-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}