{"record":{"id":"5e550522f6bc98f9","repo":"xai-org/grok-build","slug":"error-5e5505","errorCode":null,"errorMessage":"{}","messagePattern":"\\{\\}","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace/src/trust.rs","lineNumber":338,"sourceCode":"    /// Uses a unique temp file in the destination directory so concurrent\n    /// writers never share a temp path, fsyncs it for crash durability, then\n    /// renames it over the destination. `tempfile::NamedTempFile` creates the\n    /// temp with `O_EXCL` and `0600` permissions on Unix, and `persist`\n    /// performs an atomic replace (including over an existing destination on\n    /// Windows).\n    fn persist_doc(path: &Path, doc: &TrustDocument) -> io::Result<()> {\n        use std::io::Write;\n\n        let parent = path.parent().ok_or_else(|| {\n            io::Error::new(\n                io::ErrorKind::InvalidInput,\n                \"trust store path has no parent\",\n            )\n        })?;\n        std::fs::create_dir_all(parent)?;\n\n        let body = toml::to_string_pretty(doc)\n            .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;\n\n        // Unique temp in the same directory (atomic rename requires same FS).\n        let mut tmp = tempfile::NamedTempFile::new_in(parent)?;\n        tmp.write_all(body.as_bytes())?;\n        // Durably flush to disk before publishing so a crash can't leave a\n        // zero-length or stale store behind. (`File::flush` is a no-op for\n        // durability; `sync_all` is what guarantees the bytes hit disk.)\n        tmp.as_file().sync_all()?;\n        // Atomic publish.\n        tmp.persist(path).map_err(|e| e.error)?;\n        Ok(())\n    }\n}\n\n/// Compute the trust **workspace key** for a working directory.\n///\n/// The key is the canonicalized git repository root when `cwd` is inside a\n/// repo (trust applies to the whole repo), otherwise the canonicalized `cwd`.","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace/src/trust.rs#L320-L356","documentation":"After computing the parent and serializing the TrustDocument to TOML, persist_doc maps serde/serialization failures into io::ErrorKind::InvalidData. It means the in-memory document could not be rendered as TOML (e.g. a value type not representable in TOML).","triggerScenarios":"Calling the persist API with a TrustDocument containing a field TOML cannot represent (e.g. nested map keys that aren't strings, NaN/Infinity floats, unsupported enum representations).","commonSituations":"Adding a new field to TrustDocument with a type the toml crate can't serialize; storing heterogeneous maps; deserializing input from JSON and re-serializing to TOML.","solutions":["Inspect the serde error (it is the io error's source) to find the offending field","Change the field type to a TOML-compatible one (string-keyed maps, finite floats)","Round-trip the document through a test toml::to_string_pretty call in CI to catch regressions"],"exampleFix":"// before\nextra: BTreeMap<MyKey, String>, // MyKey doesn't serialize as a TOML table key\n// after\nextra: BTreeMap<String, String>,","handlingStrategy":"try-catch","validationCode":"fn toml_representable(doc: &TrustDocument) -> bool {\n    toml::to_string_pretty(doc).is_ok()\n}\nassert!(toml_representable(&doc), \"document must round-trip as TOML\");","typeGuard":null,"tryCatchPattern":"if let Err(e) = persist_doc(&path, &doc) {\n    if e.kind() == io::ErrorKind::InvalidData {\n        eprintln!(\"TOML serialize failed: {}\", e.source().map(|s| s.to_string()).unwrap_or_default());\n    }\n    return Err(e.into());\n}","preventionTips":["Keep TrustDocument fields TOML-friendly (string-keyed maps, finite floats)","Add a CI test that round-trips a sample document through toml::to_string_pretty","Avoid storing heterogeneous/dynamic maps in the document"],"tags":["io","serialization","toml","rust"],"backgroundTag":"toml-serialization-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}