BigPizzaV3/CodexPlusPlus · error
必须是 TOML table
Error message
{key} 必须是 TOML table What it means
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.
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.
Example fix
// before (config.toml) model_providers = "openai" // after (config.toml) [model_providers.openai] base_url = "https://api.openai.com/v1"
Defensive patterns
Strategy: validation
Validate before calling
fn ensure_table(doc: &toml_edit::DocumentMut, key: &str) -> bool {
matches!(doc.get(key), Some(item) if item.is_table()) || !doc.contains_key(key)
}
// check every top-level key the apply flow writes before calling it Type guard
fn is_toml_table(item: Option<&toml_edit::Item>) -> bool {
item.map(|i| i.is_table()).unwrap_or(false)
} Try / catch
match apply_relay_profile_to_home(...) {
Err(e) if e.to_string().contains("必须是 TOML table") => {
// back up config.toml, remove/repair the offending key, retry once
}
other => other?,
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- model_providers. 必须是 TOML table
- 必须是 TOML 表
- config.toml TOML 解析失败:
- config.toml TOML 解析失败:
- Dream Skin theme backup belongs to a different config.toml
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/0a7d5cb6271e0994.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-core/src/relay_config.rs:167
if enabled {
if !updated.is_empty() {
updated.push_str("\n\n");
}
updated.push_str("[features]\ngoals = true");
}
ensure_trailing_newline(updated)
}
fn table_mut_or_insert<'a>(doc: &'a mut DocumentMut, key: &str) -> anyhow::Result<&'a mut Table> {
if !doc.as_table().contains_key(key) {
doc[key] = toml_edit::table();
}
if doc.get(key).and_then(Item::as_table).is_none() {
doc[key] = toml_edit::table();
}
doc.get_mut(key)
.and_then(Item::as_table_mut)
.ok_or_else(|| anyhow::anyhow!("{key} 必须是 TOML table"))
}
fn table_mut_if_exists<'a>(doc: &'a mut DocumentMut, key: &str) -> Option<&'a mut Table> {
doc.get_mut(key).and_then(Item::as_table_mut)
}
pub fn relay_status_from_home(home: &Path) -> RelayStatus {
let auth = chatgpt_auth_status_from_home(home);
let config = relay_config_status_from_home(home);
RelayStatus {
authenticated: auth.authenticated,
auth_source: auth.source,
account_label: auth.account_label,
config_path: config.config_path,
configured: config.configured,
requires_openai_auth: config.requires_openai_auth,
has_bearer_token: config.has_bearer_token,
}View on GitHub (pinned to b1ed92e5e4)