{"record":{"id":"8bd88fed36c826b3","repo":"Hmbown/CodeWhale","slug":"failed-to-parse-config-toml-while-removing-plainte","errorCode":null,"errorMessage":"failed to parse config TOML while removing plaintext API keys; file contents were omitted","messagePattern":"failed to parse config TOML while removing plaintext API keys; file contents were omitted","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/config/src/lib.rs","lineNumber":5568,"sourceCode":"            \"failed to scrub plaintext API keys while creating config backup {}\",\n            backup.display()\n        )\n    })?;\n    persistence::atomic_write(&backup, scrubbed.as_bytes()).with_context(|| {\n        format!(\n            \"failed to create credential-free config backup {} from {}\",\n            backup.display(),\n            path.display()\n        )\n    })?;\n    Ok(())\n}\n\nfn config_toml_without_plaintext_api_keys(raw: &str) -> Result<String> {\n    let mut document = raw\n        .parse::<toml_edit::DocumentMut>()\n        .map_err(|_| {\n            anyhow::anyhow!(\n                \"failed to parse config TOML while removing plaintext API keys; file contents were omitted\"\n            )\n        })?;\n    remove_plaintext_api_keys_recursive(document.as_table_mut());\n    Ok(document.to_string())\n}\n\nfn remove_plaintext_api_keys_recursive(table: &mut dyn toml_edit::TableLike) {\n    table.remove(\"api_key\");\n    for (_, item) in table.iter_mut() {\n        if let toml_edit::Item::ArrayOfTables(tables) = item {\n            for nested in tables.iter_mut() {\n                remove_plaintext_api_keys_recursive(nested);\n            }\n        } else if let Some(nested) = item.as_table_like_mut() {\n            remove_plaintext_api_keys_recursive(nested);\n        }\n    }","sourceCodeStart":5550,"sourceCodeEnd":5586,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/config/src/lib.rs#L5550-L5586","documentation":"config_toml_without_plaintext_api_keys parses the raw config with toml_edit so plaintext API keys can be removed while preserving comments and layout. If the raw text is not parseable TOML, this sanitized error is thrown instead of exposing the file contents (which would defeat the purpose of removing secrets).","triggerScenarios":"Calling config_toml_without_plaintext_api_keys (via the plaintext-key scrubbing path) when the config file contains invalid TOML.","commonSituations":"A manually edited or corrupted config containing plaintext API keys; a migration/upgrade path that scrubs keys encountering a pre-existing syntax error.","solutions":["Fix the TOML syntax error in the config file","Validate the file with a TOML parser to find the exact line","Restore the config from a backup and re-add settings carefully","Move API keys into the proper secret storage so the scrub path is not needed"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"toml::from_str::<toml::Value>(&raw).map_err(|e| format!(\"invalid config TOML: {e}\"))?;","typeGuard":null,"tryCatchPattern":"match scrub_plaintext_keys() {\n    Ok(_) => {},\n    Err(e) => eprintln!(\"{e}; fix config TOML syntax, then move keys to secret storage\"),\n}","preventionTips":["Store API keys in secret storage, not plaintext in the config","Lint config TOML after manual edits","Version-control the config to recover from corruption"],"tags":["toml","config","security","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"}