{"record":{"id":"00cd1376009ef8b6","repo":"Hmbown/CodeWhale","slug":"failed-to-parse-config-at-file-contents-were-o","errorCode":null,"errorMessage":"failed to parse config at {}; file contents were omitted","messagePattern":"failed to parse config at (.+?); file contents were omitted","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/config/src/config_document.rs","lineNumber":30,"sourceCode":"use anyhow::{Context, Result, bail};\n\nuse crate::{\n    checked_path_exists, normalize_config_file_path, persistence, read_checked_config_file,\n    write_one_time_config_backup,\n};\n\n/// Parse the latest document under the shared write lock, apply `mutate`, and\n/// atomically persist only the resulting delta.\npub fn mutate_config_document<T, F>(path: &Path, mutate: F) -> Result<T>\nwhere\n    F: FnOnce(&mut toml_edit::DocumentMut) -> Result<T>,\n{\n    with_config_write_lock(path, |path| {\n        let original = read_optional_config(path)?;\n        let mut document = match original.as_deref() {\n            Some(raw) if !raw.trim().is_empty() => {\n                raw.parse::<toml_edit::DocumentMut>().map_err(|_| {\n                    anyhow::anyhow!(\n                        \"failed to parse config at {}; file contents were omitted\",\n                        crate::quote_os_path(path)\n                    )\n                })?\n            }\n            _ => toml_edit::DocumentMut::new(),\n        };\n        heal_extras_nesting(&mut document);\n        let result = mutate(&mut document)?;\n        let body = document.to_string();\n        if original.as_deref() == Some(body.as_str()) || (original.is_none() && body.is_empty()) {\n            return Ok(result);\n        }\n        persist_locked(path, original.as_deref(), body.as_bytes())?;\n        Ok(result)\n    })\n}\n","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/crates/config/src/config_document.rs#L12-L48","documentation":"mutate_config_document takes the shared config write lock, parses the existing file with toml_edit, applies a mutation, and persists only the delta. This error means the on-disk file failed TOML parsing, so the mutation aborted before any write. File contents are deliberately omitted from the message so config secrets never reach logs.","triggerScenarios":"Any config-mutating API call while the file contains invalid TOML syntax (unclosed string/bracket, malformed inline table) or duplicate keys, which toml_edit rejects, even when the pending mutation itself would be valid.","commonSituations":"Hand-edited config.toml with a typo; a crashed process leaving a truncated file; merge-conflict resolution introducing a duplicate key; another tool appending malformed lines.","solutions":["Validate the file with a TOML checker (taplo check or an editor TOML LSP) and fix the reported line","Check for duplicate keys: TOML forbids them; rename one of the duplicates","If unfixable, back the file up and move it aside so defaults regenerate, then reapply settings from the backup"],"exampleFix":"# before (config.toml with a duplicate key)\nmodel = \"glm-4.6\"\ntheme = \"dark\"\nmodel = \"glm-4.7\"   # error: duplicate key\n\n# after\nmodel = \"glm-4.7\"\ntheme = \"dark\"","handlingStrategy":"validation","validationCode":"// Before calling mutate_config_document, prove the file parses:\nfn config_is_editable(path: &std::path::Path) -> bool {\n    match std::fs::read_to_string(path) {\n        Ok(raw) => raw.trim().is_empty() || raw.parse::<toml_edit::DocumentMut>().is_ok(),\n        Err(_) => false,\n    }\n}","typeGuard":null,"tryCatchPattern":"On Err, stop and point the user at a TOML validator output for the quoted path; do not retry, the file will not parse differently. Offer the move-aside-and-regenerate path explicitly.","preventionTips":["Edit config.toml with a TOML-aware editor (LSP) that catches syntax and duplicate-key errors on save","Prefer Codewhale CLI commands over hand-editing so writes go through the same serializer","Back up the config before schema-upgrading versions"],"tags":["config","toml","parse","write-lock"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}