{"record":{"id":"af9c781b8f16fa40","repo":"xai-org/grok-build","slug":"refusing-to-write-import-marker-existing-config-a","errorCode":null,"errorMessage":"refusing to write import marker: existing config at {} is not valid TOML ({}). Fix the file (or move it aside) and retry.","messagePattern":"refusing to write import marker: 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":616,"sourceCode":"        .get(\"claude_compat\")\n        .and_then(|v| v.get(\"imported\"))\n        .and_then(|v| v.as_bool())\n        .unwrap_or(false)\n}\n\n/// Write `[claude_compat] imported = true` to `~/.grok/config.toml`.\n///\n/// Uses the same atomic write pattern as `save_mcp_server_config` (write to\n/// `.tmp`, then rename). Creates the file and parent directory if missing.\n/// Existing content in the file is preserved.\nfn write_import_marker(config_path: &Path) -> anyhow::Result<()> {\n    // Surface parse errors instead of silently discarding the file: an atomic\n    // rewrite would otherwise drop unrelated sections ([model], [ui], etc.)\n    // and overwrite a hand-edited config that just happens to have a trailing\n    // comma. The user can fix the TOML and retry.\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 write import marker: existing config at {} is \\\n                 not valid TOML ({}). Fix the file (or move it aside) and \\\n                 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    let table = root\n        .as_table_mut()\n        .ok_or_else(|| anyhow::anyhow!(\"config root is not a table\"))?;\n    let compat = table\n        .entry(\"claude_compat\")\n        .or_insert_with(|| TomlValue::Table(TomlMap::new()));\n    let compat_table = compat\n        .as_table_mut()","sourceCodeStart":598,"sourceCodeEnd":634,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-shell/src/claude_import.rs#L598-L634","documentation":"write_import_marker refuses to add the claude_compat.imported marker when the existing config file fails TOML parsing. Rewriting the file would drop unrelated sections ([model], [ui], etc.) from a hand-edited config, so the error surfaces the parse failure and asks the user to fix the TOML first.","triggerScenarios":"Calling mark_claude_imported (or write_import_marker) when the target config file exists but contains invalid TOML, e.g. a trailing comma or malformed table header.","commonSituations":"A user hand-edited their config file and left a trailing comma; another tool corrupted the file; a merge left partial TOML syntax behind.","solutions":["Open the config file at the path in the message and fix the TOML syntax reported by the parse error (often a trailing comma).","Temporarily move the file aside so write_import_marker creates a fresh table, then re-apply your settings.","Validate the file with a TOML linter/parser (e.g. taplo, tomlq) before retrying."],"exampleFix":"// before (config.toml)\n[ui]\ntheme = \"dark\",\n\n// after\n[ui]\ntheme = \"dark\"","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!(\"config {} invalid TOML: {}\", path.display(), e))?;\n}","typeGuard":"fn is_valid_toml_table(s: &str) -> bool {\n    toml::from_str::<toml::Value>(s)\n        .map(|v| v.is_table())\n        .unwrap_or(false)\n}","tryCatchPattern":"match write_import_marker(&path) {\n    Err(e) if e.to_string().contains(\"not valid TOML\") => {\n        eprintln!(\"Fix config TOML first: {e}\");\n    }\n    Err(e) => return Err(e),\n    Ok(()) => {}\n}","preventionTips":["Never hand-edit config TOML without validating afterwards (taplo, tomlq).","Run the import on a committed/VCS-tracked config so bad edits are revertible.","Keep one canonical serializer for the config instead of manual edits."],"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"}