BigPizzaV3/CodexPlusPlus · error
config.toml 内容不能为空
Error message
config.toml 内容不能为空
What it means
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.
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.
Example fix
// before
let config = std::fs::read_to_string(path).unwrap_or_default();
apply_relay_files_to_home(home, &config, &auth)?;
// after
let config = std::fs::read_to_string(path)?;
anyhow::ensure!(!config.trim().is_empty(), "config template is empty: {path:?}");
apply_relay_files_to_home(home, &config, &auth)?; Defensive patterns
Strategy: validation
Validate before calling
anyhow::ensure!(!config_contents.trim().is_empty(), "生成的 config.toml 为空,请检查配置生成步骤"); apply_relay_files_to_home(home, &config_contents, &auth_contents)?;
Try / catch
match apply_relay_files_to_home(home, &config, &auth) {
Ok(r) => info!("config applied, backup: {:?}", r.backup_path),
Err(e) if e.to_string().contains("config.toml 内容不能为空") => {
eprintln!("生成的配置为空:检查 build_config_toml 输入与模板文件");
Err(e)
}
Err(e) => Err(e),
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- 中转 Base URL 不能为空
- 中转 Key 不能为空
- 官方混合 API 不应在 auth.json 中保存 OPENAI_API_KEY。请清理此供应商的…
- 请填写 API 的模型名称
- API Key 为空
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/5cd326286f52f30a.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-core/src/relay_config.rs:451
base_url: &str,
bearer_token: &str,
) -> anyhow::Result<RelayApplyResult> {
apply_pure_api_config_to_home_with_protocol(
home,
base_url,
bearer_token,
RelayProtocol::Responses,
crate::protocol_proxy::protocol_proxy_port(),
)
}
pub fn apply_relay_files_to_home(
home: &Path,
config_contents: &str,
auth_contents: &str,
) -> anyhow::Result<RelayApplyResult> {
if config_contents.trim().is_empty() {
anyhow::bail!("config.toml 内容不能为空");
}
std::fs::create_dir_all(home)?;
let backup_path =
write_codex_live_atomic(home, Some(config_contents), Some(auth_contents.as_bytes()))?;
let status = relay_config_status_from_home(home);
Ok(RelayApplyResult {
config_path: status.config_path,
backup_path,
configured: status.configured,
})
}
pub fn apply_relay_files_to_home_with_common(
home: &Path,
config_contents: &str,
auth_contents: &str,View on GitHub (pinned to b1ed92e5e4)