{"record":{"id":"684f1b8d75003fc6","repo":"BigPizzaV3/CodexPlusPlus","slug":"config-toml-toml-error","errorCode":null,"errorMessage":"config.toml TOML 解析失败：{error}","messagePattern":"config\\.toml TOML 解析失败：(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/codex-plus-core/src/relay_config.rs","lineNumber":1409,"sourceCode":"fn is_custom_provider_id(provider: &str) -> bool {\n    !provider.is_empty() && !RESERVED_MODEL_PROVIDER_IDS.contains(&provider)\n}\n\nfn provider_table_exists(doc: &DocumentMut, provider_id: &str) -> bool {\n    doc.get(\"model_providers\")\n        .and_then(Item::as_table)\n        .and_then(|table| table.get(provider_id))\n        .is_some()\n}\n\nfn parse_toml_document(contents: &str) -> anyhow::Result<DocumentMut> {\n    let contents = contents.trim_start_matches('\\u{feff}');\n    if contents.trim().is_empty() {\n        Ok(DocumentMut::new())\n    } else {\n        contents\n            .parse::<DocumentMut>()\n            .map_err(|error| anyhow::anyhow!(\"config.toml TOML 解析失败：{error}\"))\n    }\n}\n\nfn remove_provider_specific_common_keys(table: &mut dyn TableLike) {\n    for key in PROVIDER_SPECIFIC_COMMON_ROOT_KEYS {\n        table.remove(key);\n    }\n    let sensitive_keys: Vec<String> = table\n        .iter()\n        .map(|(key, _)| key.to_string())\n        .filter(|key| is_provider_credential_root_key(key))\n        .collect();\n    for key in sensitive_keys {\n        table.remove(&key);\n    }\n    table.remove(\"model_providers\");\n}\n","sourceCodeStart":1391,"sourceCodeEnd":1427,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/relay_config.rs#L1391-L1427","documentation":"The config.toml loader trims a UTF-8 BOM, treats an empty file as an empty document, and otherwise parses with toml_edit::DocumentMut. When the file content is not valid TOML syntax, the parse error is wrapped as \"config.toml TOML 解析失败：{error}\". This guards all read/apply operations so they fail fast instead of silently working on a partial document.","triggerScenarios":"Any call that reads config.toml (apply_relay_profile_to_home_with_switch_rules, merge/switch flows) when the file contains syntactically invalid TOML: unclosed brackets, duplicate keys, unterminated strings, or wrong indentation for multi-line strings.","commonSituations":"Manual edits with a non-TOML-aware editor, paste of JSON instead of TOML, copy-paste losing quotes/brackets, merge conflict markers (<<<<<<<) left in the file, or an editor writing a BOM-plus-garbage file.","solutions":["Read the toml_edit error detail after 解析失败： in the message — it gives line/column; fix that exact syntax problem in config.toml.","Run the file through a TOML validator/parser to enumerate all syntax errors before retrying.","Restore config.toml from backup or from codex defaults and re-apply the profile.","Check for leftover git merge-conflict markers and stray characters near the reported line."],"exampleFix":"// before (config.toml)\nmodel = \"gpt-5\nmodel_providers = [openai]\n// after (config.toml)\nmodel = \"gpt-5\"\n[model_providers.openai]\nbase_url = \"https://api.openai.com/v1\"","handlingStrategy":"try-catch","validationCode":"fn config_toml_is_valid(path: &str) -> bool {\n    std::fs::read_to_string(path)\n        .map(|c| c.trim_start_matches('\\u{feff}').parse::<toml_edit::DocumentMut>().is_ok())\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match apply_relay_profile_to_home_with_switch_rules(...) {\n    Err(e) if e.to_string().contains(\"TOML 解析失败\") => {\n        // restore config.toml from backup, or surface the toml_edit line/column to the user\n    }\n    other => other?,\n}","preventionTips":["Back up config.toml before any manual or scripted edit","Use a TOML-aware editor/plugin with syntax checking","Never paste JSON into config.toml","Resolve git merge conflicts in config.toml before applying profiles","Strip stray BOM/garbage; the loader only tolerates a leading BOM on an otherwise valid file"],"tags":["toml","parse-error","config"],"backgroundTag":"toml-parse-error","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"}