BigPizzaV3/CodexPlusPlus · error

config.toml 内容不能为空

Error message

config.toml 内容不能为空

What it means

apply_relay_files_to_home_with_computer_use_guard 在把传入的 config.toml 内容原子写入 Codex home 之前,要求 config_contents trim 后非空。为空则 bail,不创建目录、不写文件、不产生备份。这是按「整份文件内容」应用中转配置的通用入口(computer_use_guard 变体控制是否保留实验性守护配置)。

Source

Thrown at crates/codex-plus-core/src/relay_config.rs:326

    )
}

pub fn apply_relay_files_to_home(
    home: &Path,
    config_contents: &str,
    auth_contents: &str,
) -> anyhow::Result<RelayApplyResult> {
    apply_relay_files_to_home_with_computer_use_guard(home, config_contents, auth_contents, false)
}

pub fn apply_relay_files_to_home_with_computer_use_guard(
    home: &Path,
    config_contents: &str,
    auth_contents: &str,
    preserve_computer_use_guard: bool,
) -> 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()),
        preserve_computer_use_guard,
    )?;

    let status = relay_config_status_from_home(home);
    Ok(RelayApplyResult {
        config_path: status.config_path,
        backup_path,
        configured: status.configured,
    })
}

View on GitHub (pinned to 1f431ae49b)

Solutions

  1. 调用前检查 config_contents.trim() 非空
  2. 若只想更新 auth.json,使用 clear/write 系列的其他接口而非本函数
  3. 检查 profile.config_contents 是否在保存/切换流程中被意外清空

Example fix

// before
let r = apply_relay_files_to_home(&home, "", &auth)?;

// after
let cfg = config_contents.trim();
if cfg.is_empty() {
    return Err(anyhow::anyhow!("config.toml 内容不能为空"));
}
let r = apply_relay_files_to_home(&home, cfg, &auth)?;
Defensive patterns

Strategy: validation

Validate before calling

anyhow::ensure!(!config_contents.trim().is_empty(), "config.toml 内容不能为空");
apply_relay_files_to_home_with_computer_use_guard(&home, config_contents, auth_contents, preserve)?;

Try / catch

if let Err(err) = apply_relay_files_to_home_with_computer_use_guard(&home, cfg, auth, keep) {
    if err.to_string().contains("config.toml 内容不能为空") {
        // 视为用户输入问题:提示编辑器内容为空,不要重试
    } else { return Err(err); }
}

Prevention

When it happens

Trigger: 调用 apply_relay_files_to_home* 系列函数(含 with_computer_use_guard 变体)时 config_contents 参数是空字符串或纯空白(空格/换行/BOM 之后的空白也不行——注意本函数不做 BOM 剥离,但 trim 会忽略 BOM 之外的空白)。auth_contents 为空不会触发本错误,只有 config_contents 会。

Common situations: 前端编辑器内容未加载完成就提交;从 profile 读取 config_contents 时字段为空;上游生成的 config 文本为空串;误以为传空 config 可以只更新 auth.json。

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@1f431ae49b (2026-08-16). Data as JSON: /api/errors/5cd326286f52f30a. Report an issue: GitHub.