BigPizzaV3/CodexPlusPlus · error

非法 Release asset 文件名

Error message

非法 Release asset 文件名: {name}

What it means

safe_asset_name sanitizes a GitHub Release asset filename before it is written to disk during an update. The first check rejects empty or whitespace-only names: an empty name would produce an invalid/unwritable target path, so the function bails before any path analysis.

Solutions

  1. Verify the release metadata source actually includes a non-empty `name` for every asset.
  2. Skip/filter assets with empty names before calling download_asset_to.
  3. If using a proxy or mirror of GitHub releases, confirm it forwards the asset `name` field intact.

Example fix

// before
for asset in release.assets {
    download_asset_to(&asset)?; // fails when asset.name == ""
}
// after
for asset in release.assets {
    if asset.name.trim().is_empty() { continue; }
    download_asset_to(&asset)?;
}
Defensive patterns

Strategy: validation

Validate before calling

if asset.name.trim().is_empty() {
    eprintln!("skipping unnamed release asset");
    continue;
}
let safe = safe_asset_name(&asset.name)?;

Type guard

fn valid_asset_name(name: &str) -> bool {
    !name.trim().is_empty()
        && std::path::Path::new(name).components().count() == 1
        && !matches!(name, "." | "..")
}

Try / catch

match safe_asset_name(&asset.name) {
    Ok(name) => download_to(name, bytes),
    Err(e) => { log::warn!("unusable asset name '{}': {e}", asset.name); continue; }
}

Prevention

When it happens

Trigger: download_asset_to receiving an asset whose `name` field is "" or all whitespace — e.g. a hand-crafted release manifest, a truncated API response, or deserializing an asset entry missing the name field into an empty string.

Common situations: A self-hosted/modified release JSON where the asset entry lacks a name; network truncation producing partially-parsed metadata; copying asset metadata between releases and dropping the name field.

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/301c7b08215be52c. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/update.rs:331

pub fn download_asset_to(
    release: &Release,
    bytes: &[u8],
    download_dir: &Path,
) -> anyhow::Result<PathBuf> {
    let name = release
        .asset_name
        .as_ref()
        .ok_or_else(|| anyhow::anyhow!("没有可下载的 Release asset"))?;
    let safe = safe_asset_name(name)?;
    std::fs::create_dir_all(download_dir)?;
    let path = download_dir.join(safe);
    std::fs::write(&path, bytes)?;
    Ok(path)
}

pub fn safe_asset_name(name: &str) -> anyhow::Result<String> {
    if name.trim().is_empty() {
        anyhow::bail!("非法 Release asset 文件名: {name}");
    }
    let path = Path::new(name);
    if path.components().count() != 1 {
        anyhow::bail!("非法 Release asset 文件名: {name}");
    }
    let file_name = path
        .file_name()
        .and_then(|name| name.to_str())
        .ok_or_else(|| anyhow::anyhow!("非法 Release asset 文件名: {name}"))?;
    if file_name == "." || file_name == ".." {
        anyhow::bail!("非法 Release asset 文件名: {name}");
    }
    Ok(file_name.to_string())
}

fn platform_asset_rank(name: &str) -> u8 {
    // 0 = exact match (current OS + native arch)
    // 1 = same OS, other arch (acceptable fallback, e.g. x86_64 on arm64 or vice versa)

View on GitHub (pinned to b1ed92e5e4)