{"record":{"id":"5cd326286f52f30a","repo":"BigPizzaV3/CodexPlusPlus","slug":"config-toml","errorCode":null,"errorMessage":"config.toml 内容不能为空","messagePattern":"config\\.toml 内容不能为空","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/relay_config.rs","lineNumber":451,"sourceCode":"    base_url: &str,\n    bearer_token: &str,\n) -> anyhow::Result<RelayApplyResult> {\n    apply_pure_api_config_to_home_with_protocol(\n        home,\n        base_url,\n        bearer_token,\n        RelayProtocol::Responses,\n        crate::protocol_proxy::protocol_proxy_port(),\n    )\n}\n\npub fn apply_relay_files_to_home(\n    home: &Path,\n    config_contents: &str,\n    auth_contents: &str,\n) -> anyhow::Result<RelayApplyResult> {\n    if config_contents.trim().is_empty() {\n        anyhow::bail!(\"config.toml 内容不能为空\");\n    }\n    std::fs::create_dir_all(home)?;\n\n    let backup_path =\n        write_codex_live_atomic(home, Some(config_contents), Some(auth_contents.as_bytes()))?;\n\n    let status = relay_config_status_from_home(home);\n    Ok(RelayApplyResult {\n        config_path: status.config_path,\n        backup_path,\n        configured: status.configured,\n    })\n}\n\npub fn apply_relay_files_to_home_with_common(\n    home: &Path,\n    config_contents: &str,\n    auth_contents: &str,","sourceCodeStart":433,"sourceCodeEnd":469,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/relay_config.rs#L433-L469","documentation":"Thrown by `apply_relay_files_to_home` in relay_config.rs when the `config_contents` argument is empty or whitespace-only (trimmed check). This function atomically writes config.toml and auth.json into the codex home; writing an empty config would wipe the user's live codex configuration, so it is rejected as a safety guard before any file I/O.","triggerScenarios":"Calling `apply_relay_files_to_home(home, \"\", auth)` or with a blank/whitespace-only config string; bails at relay_config.rs:451 before create_dir_all/write. Reached via all wrappers: apply_relay_files_to_home_with_common, _with_context, apply_relay_profile_files_to_home_with_context, apply_relay_profile_to_home_with_switch_rules, etc.","commonSituations":"Config generation (build_config_toml) returned an empty string due to upstream input failure; a template file was read as empty (wrong path, zero-byte file); a caller passed the wrong variable (empty placeholder) to the apply call.","solutions":["Ensure build_config_toml / your generation step produced a non-empty TOML string before calling apply.","Check the source file/template you read the config from is non-empty and read correctly.","Log the config contents (length) just before the apply call to catch empty payloads at the call site."],"exampleFix":"// before\nlet config = std::fs::read_to_string(path).unwrap_or_default();\napply_relay_files_to_home(home, &config, &auth)?;\n// after\nlet config = std::fs::read_to_string(path)?;\nanyhow::ensure!(!config.trim().is_empty(), \"config template is empty: {path:?}\");\napply_relay_files_to_home(home, &config, &auth)?;","handlingStrategy":"validation","validationCode":"anyhow::ensure!(!config_contents.trim().is_empty(), \"生成的 config.toml 为空，请检查配置生成步骤\");\napply_relay_files_to_home(home, &config_contents, &auth_contents)?;","typeGuard":null,"tryCatchPattern":"match apply_relay_files_to_home(home, &config, &auth) {\n    Ok(r) => info!(\"config applied, backup: {:?}\", r.backup_path),\n    Err(e) if e.to_string().contains(\"config.toml 内容不能为空\") => {\n        eprintln!(\"生成的配置为空：检查 build_config_toml 输入与模板文件\");\n        Err(e)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Assert build_config_toml output length > 0 immediately after generation.","Check template/source files exist and are non-empty before reading them into the config string.","Keep backups (the function already writes one) and verify restore path in tests."],"tags":["validation","relay-config","empty-field","config"],"backgroundTag":"empty-required-field","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"}