{"record":{"id":"b95ec9222b74a4f4","repo":"Hmbown/CodeWhale","slug":"failed-to-parse-original-config-for-comment-merge","errorCode":null,"errorMessage":"failed to parse original config for comment merge; file contents were omitted","messagePattern":"failed to parse original config for comment merge; file contents were omitted","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/config/src/lib.rs","lineNumber":5600,"sourceCode":"            }\n        } else if let Some(nested) = item.as_table_like_mut() {\n            remove_plaintext_api_keys_recursive(nested);\n        }\n    }\n}\n\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","sourceCodeStart":5582,"sourceCodeEnd":5618,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/config/src/lib.rs#L5582-L5618","documentation":"merge_and_preserve_comments re-parses the original config text with toml_edit to merge newly serialized settings while keeping comments. If the original raw text cannot be parsed, this error is thrown with contents omitted.","triggerScenarios":"Calling merge_and_preserve_comments(serialized, original_raw) where original_raw is invalid TOML (e.g. the on-disk config was edited or corrupted between read and merge).","commonSituations":"User hand-edited the config into invalid TOML, then the app tried to save settings; external sync tools wrote malformed content that the app then tried to merge into.","solutions":["Fix the TOML syntax in the original config file, then retry the save","Validate the original config with a TOML parser to locate the error","Restore a valid config from backup so the comment-preserving merge can proceed","Avoid editing the config while the app is running/saving"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"toml::from_str::<toml::Value>(&original_raw).map_err(|e| format!(\"original config invalid: {e}\"))?;","typeGuard":null,"tryCatchPattern":"match save_settings() {\n    Ok(_) => {},\n    Err(e) => eprintln!(\"{e}; the on-disk config is not valid TOML — fix or restore it before saving\"),\n}","preventionTips":["Close the app before hand-editing the config","Lint the config after manual edits","Restore from version control instead of patching broken files"],"tags":["toml","config","merge","parse-error"],"backgroundTag":"schema-validation-failed","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}