{"record":{"id":"53e72087b2f5abc6","repo":"rtk-ai/rtk","slug":"config-toml-is-not-valid-toml-e","errorCode":null,"errorMessage":"config.toml is not valid TOML: {e}","messagePattern":"config\\.toml is not valid TOML: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/core/config.rs","lineNumber":395,"sourceCode":"        }\n\n        let content = toml::to_string_pretty(self)?;\n        std::fs::write(&path, content)?;\n        Ok(())\n    }\n\n    pub fn create_default() -> Result<PathBuf> {\n        let config = Config::default();\n        config.save()?;\n        get_config_path()\n    }\n}\n\nfn apply_recall_mode(content: &str, mode: crate::core::retriever::RecoveryMode) -> Result<String> {\n    use crate::core::retriever::RecoveryMode;\n    let mut doc: toml_edit::DocumentMut = content\n        .parse()\n        .map_err(|e| anyhow::anyhow!(\"config.toml is not valid TOML: {e}\"))?;\n\n    let legacy = doc.remove(\"tee\");\n    let retriever_is_table = doc\n        .get(\"retriever\")\n        .is_some_and(|item| item.as_table_like().is_some());\n    if !retriever_is_table {\n        doc[\"retriever\"] = toml_edit::Item::Table(toml_edit::Table::new());\n    }\n    let mode_str = match mode {\n        RecoveryMode::Sqlite => \"sqlite\",\n        RecoveryMode::Tee => \"tee\",\n        RecoveryMode::Disabled => \"disabled\",\n    };\n    doc[\"retriever\"][\"mode\"] = toml_edit::value(mode_str);\n\n    if let Some(legacy) = legacy.as_ref().and_then(|i| i.as_table_like()) {\n        let tee = LegacyTeeConfig {\n            enabled: legacy","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/rtk-ai/rtk/blob/0924356b4caba4989607227b7c8824d3d8098719/src/core/config.rs#L377-L413","documentation":"apply_recall_mode parses the user's config.toml with toml_edit before rewriting the retriever/tee sections. If the file content is not syntactically valid TOML, the parse fails and the function wraps the toml_edit error in this anyhow error.","triggerScenarios":"Calling set_recall_mode (or the internal apply_recall_mode in tests) while ~/.config/rtk/config.toml (or the config content passed in) contains a TOML syntax error: unclosed string, duplicate key, missing bracket on a table header, stray tab, etc.","commonSituations":"Hand-edited config.toml with a typo; a previous crashed/partial write; pasting JSON into a TOML file; merging conflicting edits leaving duplicated keys.","solutions":["Open config.toml and fix the TOML syntax error reported after the colon (line/column are included by toml_edit).","Validate the file with a TOML linter or `python -c \"import tomllib;tomllib.load(open('config.toml','rb'))\"`.","If unsure, back up and delete/recreate config.toml, then re-run the command to regenerate defaults."],"exampleFix":"// before (broken)\nretriever = sqlite\ntee = \n// after\n[retriever]\nmode = \"sqlite\"","handlingStrategy":"try-catch","validationCode":"import tomllib\nwith open('config.toml','rb') as f:\n    tomllib.load(f)  # raises on invalid TOML before running rtk","typeGuard":null,"tryCatchPattern":"match rtk_set_recall_mode(mode) {\n    Err(e) if e.to_string().contains(\"not valid TOML\") => {\n        eprintln!(\"Fix config.toml first: {e}\");\n        // open editor / restore backup\n    }\n    Err(e) => return Err(e),\n    Ok(_) => (),\n}","preventionTips":["Validate config.toml with a TOML parser after every hand edit","Keep a known-good backup of config.toml","Use rtk commands instead of manual edits to change settings"],"tags":["toml","config","parsing"],"backgroundTag":"schema-validation-failed","analyzedSha":"0924356b4caba4989607227b7c8824d3d8098719","analyzedAt":"2026-09-19T19:25:29.612Z","contentChangedAt":"2026-09-19T19:25:29.612Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}