{"record":{"id":"0a7d5cb6271e0994","repo":"BigPizzaV3/CodexPlusPlus","slug":"key-toml-table","errorCode":null,"errorMessage":"{key} 必须是 TOML table","messagePattern":"(.+?) 必须是 TOML table","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/relay_config.rs","lineNumber":167,"sourceCode":"    if enabled {\n        if !updated.is_empty() {\n            updated.push_str(\"\\n\\n\");\n        }\n        updated.push_str(\"[features]\\ngoals = true\");\n    }\n    ensure_trailing_newline(updated)\n}\n\nfn table_mut_or_insert<'a>(doc: &'a mut DocumentMut, key: &str) -> anyhow::Result<&'a mut Table> {\n    if !doc.as_table().contains_key(key) {\n        doc[key] = toml_edit::table();\n    }\n    if doc.get(key).and_then(Item::as_table).is_none() {\n        doc[key] = toml_edit::table();\n    }\n    doc.get_mut(key)\n        .and_then(Item::as_table_mut)\n        .ok_or_else(|| anyhow::anyhow!(\"{key} 必须是 TOML table\"))\n}\n\nfn table_mut_if_exists<'a>(doc: &'a mut DocumentMut, key: &str) -> Option<&'a mut Table> {\n    doc.get_mut(key).and_then(Item::as_table_mut)\n}\n\npub fn relay_status_from_home(home: &Path) -> RelayStatus {\n    let auth = chatgpt_auth_status_from_home(home);\n    let config = relay_config_status_from_home(home);\n    RelayStatus {\n        authenticated: auth.authenticated,\n        auth_source: auth.source,\n        account_label: auth.account_label,\n        config_path: config.config_path,\n        configured: config.configured,\n        requires_openai_auth: config.requires_openai_auth,\n        has_bearer_token: config.has_bearer_token,\n    }","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/relay_config.rs#L149-L185","documentation":"table_mut_or_insert in relay_config.rs ensures a top-level TOML key exists as a table (inserting an empty one if missing), then returns it as a mutable &mut Table. The error fires when the key exists in config.toml but its value is NOT a table (e.g. a string, integer, array or inline value), so as_table_mut() returns None. It is an internal invariant violation caused by user-edited config that conflicts with the structure the library expects.","triggerScenarios":"Called from set_codex_goals_feature_in_home, merge_common_config_into_config and ensure_provider_table. Triggered whenever config.toml contains e.g. `model_providers = \"oops\"`, `mcp_servers = 42`, or `profiles = [\"a\"]` and any apply/merge operation needs to write into that key.","commonSituations":"Users hand-editing config.toml and accidentally replacing a table with a scalar (adding `=` instead of `[section]`), tools/scripts overwriting a section with a plain string, or a partially corrupted config after an interrupted write.","solutions":["Open ~/.codex/config.toml and find the key named in the error message; remove or fix it so it is a TOML table (`[key]`), not a scalar or array.","Temporarily rename/delete the offending key and re-run the apply so the library recreates it as a table.","Validate the file with a TOML linter/type expectation before applying (e.g. parse with toml_edit and check `doc.get(key).and_then(Item::as_table).is_some()`).","Restore config.toml from a backup taken before the manual edit."],"exampleFix":"// before (config.toml)\nmodel_providers = \"openai\"\n// after (config.toml)\n[model_providers.openai]\nbase_url = \"https://api.openai.com/v1\"","handlingStrategy":"validation","validationCode":"fn ensure_table(doc: &toml_edit::DocumentMut, key: &str) -> bool {\n    matches!(doc.get(key), Some(item) if item.is_table()) || !doc.contains_key(key)\n}\n// check every top-level key the apply flow writes before calling it","typeGuard":"fn is_toml_table(item: Option<&toml_edit::Item>) -> bool {\n    item.map(|i| i.is_table()).unwrap_or(false)\n}","tryCatchPattern":"match apply_relay_profile_to_home(...) {\n    Err(e) if e.to_string().contains(\"必须是 TOML table\") => {\n        // back up config.toml, remove/repair the offending key, retry once\n    }\n    other => other?,\n}","preventionTips":["Never replace a [section] with a scalar when hand-editing config.toml","Back up config.toml before manual edits","Run a TOML structural check on config.toml after external tools touch it","Keep edits inside existing tables rather than reassigning whole keys"],"tags":["toml","config","type-mismatch"],"backgroundTag":"config-type-mismatch","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}