{"record":{"id":"e2cb5d0071525608","repo":"xai-org/grok-build","slug":"refusing-to-import-existing-config-at-is-not-v","errorCode":null,"errorMessage":"refusing to import: existing config at {} is not valid TOML ({}). Fix the file (or move it aside) and retry.","messagePattern":"refusing to import: existing config at (.+?) is not valid TOML \\((.+?)\\)\\. Fix the file \\(or move it aside\\) and retry\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-shell/src/claude_import.rs","lineNumber":769,"sourceCode":"    /// Paths of config files that were modified.\n    pub modified_files: Vec<String>,\n}\n\nimpl ImportResult {\n    pub fn total(&self) -> usize {\n        self.global_count + self.project_count\n    }\n}\n\n/// Apply items to a single config.toml file using atomic write.\nfn apply_items_to_config(config_path: &Path, items: &[ImportableItem]) -> anyhow::Result<usize> {\n    // Read existing TOML. Surface parse errors instead of silently\n    // discarding the file: an atomic rewrite would otherwise drop\n    // unrelated sections ([model], [ui], etc.) and overwrite a hand-edited\n    // config that just happens to have a trailing comma.\n    let mut root: TomlValue = match std::fs::read_to_string(config_path) {\n        Ok(s) => toml::from_str(&s).map_err(|e| {\n            anyhow::anyhow!(\n                \"refusing to import: existing config at {} is not valid TOML \\\n                 ({}). Fix the file (or move it aside) and retry.\",\n                config_path.display(),\n                e\n            )\n        })?,\n        Err(e) if e.kind() == std::io::ErrorKind::NotFound => TomlValue::Table(TomlMap::new()),\n        Err(e) => return Err(e.into()),\n    };\n\n    let table = root\n        .as_table_mut()\n        .ok_or_else(|| anyhow::anyhow!(\"config root is not a table\"))?;\n\n    let mut count = 0usize;\n\n    // Group items by type.\n    let mut permissions: Vec<&PermissionRule> = Vec::new();","sourceCodeStart":751,"sourceCodeEnd":787,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-shell/src/claude_import.rs#L751-L787","documentation":"apply_items_to_config refuses to import Claude settings when the existing config file is not valid TOML. An atomic rewrite would silently discard unrelated sections ([model], [ui], etc.) and overwrite hand-edited content, so the parse error is surfaced instead.","triggerScenarios":"Calling apply_import (which calls apply_items_to_config) while the target config file exists but has invalid TOML, e.g. a trailing comma after a value.","commonSituations":"Hand-edited config with a stray trailing comma; partial write from a crashed editor; config generated by another tool with syntax errors.","solutions":["Fix the TOML syntax reported in the error at the given config path, then re-run the import.","Move the invalid file aside so the import starts from an empty table, then re-apply settings.","Run a TOML validator on the file before invoking the import."],"exampleFix":"// before (config.toml)\n[permission]\nallow = [\"bash\"],\n\n// after\n[permission]\nallow = [\"bash\"]","handlingStrategy":"validation","validationCode":"if path.exists() {\n    let s = std::fs::read_to_string(&path)?;\n    toml::from_str::<toml::Value>(&s)\n        .map_err(|e| anyhow::anyhow!(\"{} is not valid TOML: {}\", path.display(), e))?;\n}","typeGuard":"fn parses_as_toml(s: &str) -> bool {\n    toml::from_str::<toml::Value>(s).is_ok()\n}","tryCatchPattern":"match apply_import(items, &path) {\n    Err(e) if e.to_string().contains(\"not valid TOML\") => {\n        eprintln!(\"Fix the TOML syntax before importing: {e}\");\n    }\n    Err(e) => return Err(e),\n    Ok(n) => println!(\"imported {n} items\"),\n}","preventionTips":["Run the import against a config under version control so bad edits can be reverted.","Validate TOML after every manual edit (taplo check).","Avoid trailing commas, which TOML forbids but JSON habit encourages."],"tags":["toml","config","parse-error"],"backgroundTag":"invalid-toml-config","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}