{"record":{"id":"ec84203b77529e0a","repo":"nikivdev/code","slug":"expected-to-be-a-table-in-global-flow-config","errorCode":null,"errorMessage":"expected [{}] to be a table in global flow config","messagePattern":"expected \\[(.+?)\\] to be a table in global flow config","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ai.rs","lineNumber":9481,"sourceCode":"        return Ok(toml::value::Table::new());\n    }\n\n    let value: TomlValue =\n        toml::from_str(&content).with_context(|| format!(\"failed to parse {}\", path.display()))?;\n    value\n        .as_table()\n        .cloned()\n        .ok_or_else(|| anyhow::anyhow!(\"global flow config must be a TOML table\"))\n}\n\nfn ensure_toml_table<'a>(\n    root: &'a mut toml::value::Table,\n    key: &str,\n) -> Result<&'a mut toml::value::Table> {\n    let needs_insert = !matches!(root.get(key), Some(TomlValue::Table(_)));\n    if needs_insert {\n        if root.contains_key(key) {\n            bail!(\"expected [{}] to be a table in global flow config\", key);\n        }\n        root.insert(key.to_string(), TomlValue::Table(toml::value::Table::new()));\n    }\n    root.get_mut(key)\n        .and_then(TomlValue::as_table_mut)\n        .ok_or_else(|| anyhow::anyhow!(\"expected [{}] to be a table in global flow config\", key))\n}\n\nfn write_string_atomically(path: &Path, content: &str) -> Result<()> {\n    let parent = path\n        .parent()\n        .ok_or_else(|| anyhow::anyhow!(\"missing parent for {}\", path.display()))?;\n    fs::create_dir_all(parent)?;\n    let temp = parent.join(format!(\n        \".{}.tmp-{}-{}\",\n        path.file_name()\n            .and_then(|value| value.to_str())\n            .unwrap_or(\"flow.toml\"),","sourceCodeStart":9463,"sourceCodeEnd":9499,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/ai.rs#L9463-L9499","documentation":"When Flow edits the global TOML config, it ensures a given key holds a table, inserting a new table only if the key is absent. If the key exists but its value is NOT a table (e.g. a string, integer, or array), the function refuses to overwrite the existing value and bails; the same message is returned if the value cannot be borrowed as a mutable table.","triggerScenarios":"Running a command that writes a `[section]` into the global flow config (e.g. enabling Codex global settings) while the global config file already defines that key as a scalar or array — e.g. `daemon = 3` instead of `[daemon]`.","commonSituations":"Hand-edited ~/.config/flow config where a section was written as a plain key/value; an older config format or migration left a scalar where the new code expects a table; automated scripts appending settings that collide with table keys.","solutions":["Open the global flow config file and change the offending key from a scalar/array to a table: `key = \"x\"` → `[key]\\nfield = \"x\"`","Or delete the conflicting key and re-run the command so it inserts a fresh empty table","Back up the config first, then validate the TOML (e.g. with a TOML linter) before re-running"],"exampleFix":"// before (global flow config, invalid)\ndaemon = 3\n// after\n[daemon]\nenabled = true","handlingStrategy":"validation","validationCode":"// Shell/Rust: inspect the global config TOML before running commands that write sections\n# fail if the target key is not a table\npython3 -c \"import tomllib,sys; c=tomllib.load(open('global-flow-config.toml','rb')); k='daemon'; assert not (k in c and not isinstance(c[k], dict)), f'{k} is not a table'\"","typeGuard":"fn is_toml_table(v: &toml::Value) -> bool {\n    matches!(v, toml::Value::Table(_))\n}","tryCatchPattern":"match enable_global_flow_config(root, \"daemon\") {\n    Ok(table) => { /* edit table */ }\n    Err(e) if e.to_string().contains(\"to be a table in global flow config\") => {\n        let key = /* extract from message */;\n        eprintln!(\"Fix [{}]: replace the scalar/array value with a [{}] section in the global config\", key, key);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Validate the global flow config with a TOML linter after hand edits","Never define keys as scalars/arrays that later commands write as [section] tables","Back up the global config before running commands that mutate it","When migrating config formats, run the project's migration/doctor tooling instead of hand-editing"],"tags":["toml","config","schema-validation","cli"],"backgroundTag":"config-schema-mismatch","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}