{"record":{"id":"2e32a42ceda3c26e","repo":"Hmbown/CodeWhale","slug":"failed-to-parse-serialized-config-for-comment-merg","errorCode":null,"errorMessage":"failed to parse serialized config for comment merge; file contents were omitted","messagePattern":"failed to parse serialized config for comment merge; file contents were omitted","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/config/src/lib.rs","lineNumber":5336,"sourceCode":"\n/// Merge comments and formatting from an original TOML file into a\n/// freshly serialized document so user annotations (comments, whitespace,\n/// disabled keys) survive config rewrites.\n///\n/// `original_raw` is the raw text of the file before the change; the\n/// function parses it internally with [`toml_edit`] so callers stay free\n/// of that dependency.\npub fn merge_and_preserve_comments(serialized: &str, original_raw: &str) -> Result<String> {\n    let original = original_raw\n        .parse::<toml_edit::DocumentMut>()\n        .map_err(|_| {\n            anyhow::anyhow!(\n                \"failed to parse original config for comment merge; file contents were omitted\"\n            )\n        })?;\n\n    let mut new_doc = serialized.parse::<toml_edit::DocumentMut>().map_err(|_| {\n        anyhow::anyhow!(\n            \"failed to parse serialized config for comment merge; file contents were omitted\"\n        )\n    })?;\n\n    // Reuse the original document’s trailing text (file-footer comments /\n    // disabled keys) so they survive the rewrite.\n    new_doc.set_trailing(original.trailing().clone());\n\n    // Copy the top-level table's decor (document-header comments, whitespace\n    // before the first key) which `toml_edit` stores on the root `Table` itself.\n    *new_doc.as_table_mut().decor_mut() = original.as_table().decor().clone();\n\n    merge_decor_table(new_doc.as_table_mut(), original.as_table());\n\n    Ok(new_doc.to_string())\n}\n\n/// Recursively copy `decor` (prefix/suffix comments and whitespace) from","sourceCodeStart":5318,"sourceCodeEnd":5354,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/crates/config/src/lib.rs#L5318-L5354","documentation":"merge_and_preserve_comments also parses the freshly serialized document it was given. This arm failing means the serialized input itself is invalid TOML: an internal invariant violation, because the caller just produced it via TOML serialization. It does not indicate anything broken on disk.","triggerScenarios":"A custom caller passes a hand-constructed or corrupted serialized string that is not valid TOML, or a serializer bug produced invalid output. Normal save flows cannot reach this arm.","commonSituations":"Mostly embedders and tests that build the serialized text themselves; effectively a guard against programmer error rather than user state.","solutions":["If you call this API directly, ensure the first argument comes from real TOML serialization (toml::to_string or DocumentMut::to_string)","If the argument came from Codewhale's own serializer, file a bug describing the operation that produced it","Do not patch the serialized text with string surgery; regenerate it"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Prove the serialized text parses before merging:\nfn serialized_is_valid(serialized: &str) -> bool {\n    serialized.parse::<toml_edit::DocumentMut>().is_ok()\n}","typeGuard":null,"tryCatchPattern":"This arm indicates a bug in the producer of the serialized text; catch it, assert loudly (or file an issue), and never write the malformed output to disk.","preventionTips":["Always generate the serialized argument via a TOML serializer, never string concatenation","In tests, round-trip every serialized document through parse before asserting on merges"],"tags":["config","toml","parse","invariant"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}