{"record":{"id":"0c73a51aff3be37c","repo":"xai-org/grok-build","slug":"config-root-is-not-a-table","errorCode":null,"errorMessage":"config root is not a table","messagePattern":"config root is not a table","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-shell/src/claude_import.rs","lineNumber":629,"sourceCode":"    // 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()\n        .ok_or_else(|| anyhow::anyhow!(\"[claude_compat] is not a table\"))?;\n    compat_table.insert(\"imported\".to_string(), TomlValue::Boolean(true));\n\n    let toml_str = toml::to_string_pretty(&root)?;\n    if let Some(parent) = config_path.parent() {\n        std::fs::create_dir_all(parent)?;\n    }\n    let tmp = config_path.with_extension(\"toml.tmp\");\n    // Best-effort cleanup of the .tmp file if either write or rename fails so\n    // a failed marker write doesn't leave a stale artefact next to the real\n    // config (otherwise the next attempt would inherit a half-written file\n    // before the rename clobbers it).\n    if let Err(e) = std::fs::write(&tmp, &toml_str) {","sourceCodeStart":611,"sourceCodeEnd":647,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-shell/src/claude_import.rs#L611-L647","documentation":"write_import_marker parsed the config but its root value is not a TOML table, so a [claude_compat] section cannot be added as a table entry. The library requires the document root to be a table to insert sections.","triggerScenarios":"The config file's top-level TOML value is a non-table (e.g. a bare array or string), then mark_claude_imported/write_import_marker is called.","commonSituations":"A config file that accidentally contains only a TOML array like [\"a\", \"b\"] or a scalar value instead of key/value sections.","solutions":["Rewrite the config so its root is a table of key = value pairs / [sections].","Move the file aside and let the import create a fresh table-based config.","Validate the root is a table with tomlq before importing."],"exampleFix":"// before (config.toml)\n[\"a\", \"b\"]\n\n// after\n[claude_compat]\nimported = true","handlingStrategy":"validation","validationCode":"let root: toml::Value = toml::from_str(&std::fs::read_to_string(&path)?)?;\nif !root.is_table() {\n    anyhow::bail!(\"config root must be a TOML table\");\n}","typeGuard":"fn has_table_root(s: &str) -> bool {\n    toml::from_str::<toml::Value>(s).map(|v| v.is_table()).unwrap_or(false)\n}","tryCatchPattern":"match write_import_marker(&path) {\n    Err(e) if e.to_string().contains(\"root is not a table\") => {\n        std::fs::write(&path, \"\")?;\n        write_import_marker(&path)?;\n    }\n    r => r?,\n}","preventionTips":["Ensure configs always start with key = value or [section] syntax, never a bare array/scalar.","Validate root type with tomlq before importing.","Regenerate the config from a template if its structure is unknown."],"tags":["toml","config","schema"],"backgroundTag":"invalid-toml-config","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}