{"record":{"id":"23938f3745dd4087","repo":"BigPizzaV3/CodexPlusPlus","slug":"config-toml-toml-error-23938f","errorCode":null,"errorMessage":"config.toml TOML 解析失败：{error}","messagePattern":"config\\.toml TOML 解析失败：(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/settings.rs","lineNumber":1665,"sourceCode":"    })\n}\n\nfn active_provider_id(doc: &DocumentMut) -> Option<String> {\n    doc.get(\"model_provider\")\n        .and_then(Item::as_str)\n        .map(str::trim)\n        .filter(|provider| !provider.is_empty())\n        .map(ToString::to_string)\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 settings_to_object(settings: &BackendSettings) -> Map<String, Value> {\n    match serde_json::to_value(settings).unwrap_or_else(|_| Value::Object(Map::new())) {\n        Value::Object(map) => map,\n        _ => Map::new(),\n    }\n}\n\nfn normalize_settings_config_sections(mut settings: BackendSettings) -> BackendSettings {\n    settings.ccs_db_path = settings.ccs_db_path.trim().to_string();\n    let (common, extracted_context) =\n        split_context_config_sections(&settings.relay_common_config_contents);\n    let context = join_config_sections(&[\n        settings.relay_context_config_contents.as_str(),\n        extracted_context.as_str(),\n    ]);","sourceCodeStart":1647,"sourceCodeEnd":1683,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/settings.rs#L1647-L1683","documentation":"The settings loader strips a BOM and, if the file is non-empty, parses config.toml into a toml_edit DocumentMut. A syntactically invalid TOML file raises this error, embedding the parser's diagnostic. Unlike empty files (treated as an empty document), any parse error is fatal so corrupted configs are not silently rewritten.","triggerScenarios":"config.toml contains malformed TOML: unclosed string/bracket, duplicate keys, tab indentation where disallowed, invalid escape sequences, mixed value types on one key, or manual edit typos.","commonSituations":"Hand-editing config.toml with a plain text editor and breaking syntax; a crashed write leaving a truncated file; copying settings with smart quotes; merging profiles producing duplicate keys.","solutions":["Read the embedded {error} message for the exact line/column, then fix that syntax in config.toml.","Validate the file with a TOML linter or paste it into a TOML validator before saving.","Restore config.toml from a backup or regenerate it via the manager UI.","Check for BOM/encoding issues or truncated writes (file ends mid-statement) and rewrite the file cleanly."],"exampleFix":"// before (config.toml)\nmodel = \"gpt-5\nmodel_providers = [unclosed\n// after\nmodel = \"gpt-5\"\nmodel_providers = []","handlingStrategy":"validation","validationCode":"// Validate TOML before handing it to the settings API\nconst toml = require('toml');\nfunction isValidToml(text: string): boolean {\n  try { toml.parse(text.replace(/^\\uFEFF/, '')); return true; } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await api.loadSettings();\n} catch (e) {\n  if (String(e).startsWith('config.toml TOML 解析失败')) {\n    log.error(e); // message embeds exact line/column\n    promptConfigRepair();\n  } else { throw e; }\n}","preventionTips":["Edit config.toml with a TOML-aware editor/validator.","Never hand-edit with word processors (smart quotes break TOML).","Write config atomically (temp file + rename) to avoid truncation.","Keep backups of the last known-good config.toml."],"tags":["toml","config","parse-error"],"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"}