{"record":{"id":"28c2d918de1abe96","repo":"xai-org/grok-build","slug":"refusing-to-rewrite-unparseable-e","errorCode":null,"errorMessage":"refusing to rewrite unparseable {}: {e}","messagePattern":"refusing to rewrite unparseable (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-shell/src/util/config/mcp.rs","lineNumber":827,"sourceCode":"        .map_err(|e| anyhow::anyhow!(\"failed to write {}: {e}\", path.display()))?;\n    Ok(true)\n}\n\n/// Flip sticky project `enabled = false` → true with toml_edit (comments kept).\nasync fn clear_sticky_project_disabled_at(\n    path: &std::path::Path,\n    server_name: &str,\n) -> Result<bool> {\n    let original = match tokio::fs::read_to_string(path).await {\n        Ok(s) => s,\n        Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(false),\n        Err(e) => {\n            return Err(anyhow::anyhow!(\"failed to read {}: {e}\", path.display()));\n        }\n    };\n    let mut doc: toml_edit::DocumentMut = original\n        .parse()\n        .map_err(|e| anyhow::anyhow!(\"refusing to rewrite unparseable {}: {e}\", path.display()))?;\n\n    let Some(servers) = doc\n        .get_mut(\"mcp_servers\")\n        .and_then(|item| item.as_table_like_mut())\n    else {\n        return Ok(false);\n    };\n    let Some(entry) = servers.get_mut(server_name) else {\n        return Ok(false);\n    };\n    let Some(server_table) = entry.as_table_like_mut() else {\n        return Ok(false);\n    };\n    if server_table.get(\"enabled\").and_then(|v| v.as_bool()) != Some(false) {\n        return Ok(false);\n    }\n    server_table.insert(\"enabled\", toml_edit::value(true));\n","sourceCodeStart":809,"sourceCodeEnd":845,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-shell/src/util/config/mcp.rs#L809-L845","documentation":"clear_sticky_project_disabled_at uses toml_edit::DocumentMut so comments and formatting survive edits. If the existing file fails to parse as TOML, the library refuses to rewrite it — deliberately avoiding destroying a hand-maintained (or partially corrupted) config, and instead throws this error naming the file and parse error.","triggerScenarios":"save_mcp_server_enabled_in / enable_unstick_only_touches_nearest_project_definition / restore_mcp_server_enabled_after_enable_scopes_tiers encounter a project config file containing invalid TOML (unclosed string, duplicate key, bad syntax).","commonSituations":"Manual edits with typos; a merge conflict marker left in the file (<<<<<<<); truncated write from a crash; an editor saving non-UTF8 or garbled content.","solutions":["Run a TOML linter/parser on the file and fix the reported syntax error","Remove merge-conflict markers or restore the file from version control","If the file is disposable, delete it and let the tool regenerate a clean config","Re-run the command once the file parses"],"exampleFix":"// before (config.toml)\n<<<<<<< HEAD\n[mcp_servers.foo]\n// after (config.toml)\n[mcp_servers.foo]\nenabled = false","handlingStrategy":"validation","validationCode":"// validate before letting toml_edit touch the file\nlet src = std::fs::read_to_string(path)?;\nif src.contains(\"<<<<<<<\") {\n    return Err(\"merge conflict markers in config\".into());\n}\nlet _doc: toml_edit::DocumentMut = src.parse().map_err(|e| format!(\"invalid TOML: {e}\"))?;","typeGuard":"fn parses_as_toml(src: &str) -> bool {\n    src.parse::<toml_edit::DocumentMut>().is_ok()\n}","tryCatchPattern":"match result {\n    Err(e) if e.to_string().starts_with(\"refusing to rewrite unparseable\") => {\n        eprintln!(\"fix TOML syntax in the named file or restore from VCS: {e}\");\n    }\n    r => r?,\n}","preventionTips":["Run a TOML linter after every manual config edit","Resolve merge conflicts in config files before running the tool","Keep configs in git so broken edits can be reverted"],"tags":["toml","parse-error","config"],"backgroundTag":"toml-parse-error","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}