BigPizzaV3/CodexPlusPlus · error · anyhow::Error

会话 ID 为空

Error message

会话 ID 为空

What it means

export_rollout trims the session_id argument and rejects it outright when the result is empty. A session ID is required to locate the native rollout file on disk, so an empty identifier is an invalid argument rather than a lookup miss.

Solutions

  1. Pass a non-empty session ID obtained from session listing or thread metadata
  2. Validate/trim the ID at the caller (UI/API layer) before invoking export_rollout
  3. Check where the ID originates — a failed prior lookup may have defaulted it to ""

Example fix

// before
export_rollout(&home, &session_id).unwrap();
// after
let id = session_id.trim();
if id.is_empty() {
    anyhow::bail!("请提供有效的会话 ID");
}
export_rollout(&home, id)?;
Defensive patterns

Strategy: validation

Validate before calling

let id = session_id.trim();
if id.is_empty() { anyhow::bail!("session_id 不能为空"); }

Type guard

fn valid_session_id(s: &str) -> Option<&str> {
    let t = s.trim();
    if t.is_empty() { None } else { Some(t) }
}

Prevention

When it happens

Trigger: Calling export_rollout(home, "") or export_rollout(home, " ") — an empty or whitespace-only session ID string.

Common situations: UI form left blank; a variable holding the session ID was never populated (empty string default); trimming removed a placeholder of spaces.

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


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/4b3ee579d8e3eb07. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/session_share.rs:183

    let title = source_path
        .file_stem()
        .and_then(|value| value.to_str())
        .unwrap_or("导入的会话");
    import_rollout(
        home,
        &json!({
            "kind": "codex-rollout",
            "session_id": session_id,
            "content": content,
            "title": title,
        }),
    )
}

pub fn export_rollout(home: &Path, session_id: &str) -> anyhow::Result<Value> {
    let session_id = session_id.trim();
    if session_id.is_empty() {
        bail!("会话 ID 为空");
    }
    let path =
        find_rollout(home, session_id).ok_or_else(|| anyhow::anyhow!("找不到原生会话文件"))?;
    let bytes = fs::read(&path).with_context(|| format!("读取会话文件失败:{}", path.display()))?;
    if bytes.len() > MAX_ROLLOUT_BYTES {
        bail!("会话文件超过分享大小限制");
    }
    let content = String::from_utf8(bytes).context("会话文件不是有效的 UTF-8")?;
    Ok(json!({
        "status": "ok",
        "kind": "codex-rollout",
        "session_id": session_id,
        "content": content,
        "filename": path.file_name().and_then(|value| value.to_str()).unwrap_or("rollout.jsonl"),
    }))
}

pub fn import_rollout(home: &Path, payload: &Value) -> anyhow::Result<Value> {

View on GitHub (pinned to b1ed92e5e4)