BigPizzaV3/CodexPlusPlus · error

无效的主题市场相对路径

Error message

无效的主题市场相对路径

What it means

`validate_market_path` enforces the shape of relative asset paths used in market manifests: non-empty, at most 256 bytes, no leading `/`, no backslashes, and no `?`, `#`, or NUL characters. Any violation aborts with this error before the path is ever joined to the base URL or used on the filesystem. The first bail covers the whole-string rules; the second (line 359) covers per-segment rules.

Solutions

  1. Rewrite the manifest path fields as clean relative paths: no leading slash, forward slashes only, no query strings or fragments (e.g. `assets/skin.png`).
  2. If a theme has no preview/image, check whether the schema permits omission rather than an empty string; otherwise supply a valid relative path.
  3. Keep paths under 256 bytes; shorten overly long directory/file names on the server.
  4. Re-fetch or re-publish the manifest after fixing, and clear the stale cache in the state dir.

Example fix

// manifest theme entry
// before
"image": "/assets/skin.png?v=2"
// after
"image": "assets/skin.png"
Defensive patterns

Strategy: validation

Validate before calling

fn plausible_rel_path(p: &str) -> bool {
    !p.is_empty() && p.len() <= 256
        && !p.starts_with('/')
        && !p.contains('\\')
        && !p.contains(['?', '#', '\0'])
}

Type guard

fn as_rel_path(s: &str) -> Option<&str> {
    (!s.is_empty() && s.len() <= 256 && !s.starts_with('/') && !s.contains('\\') && !s.contains(['?', '#', '\0'])).then_some(s)
}

Try / catch

match install_market_theme_from_base(...).await {
    Err(e) if e.to_string().contains("相对路径") => {
        eprintln!("manifest path field malformed; fix the market manifest");
    }
    other => other?,
}

Prevention

When it happens

Trigger: `validate_market_theme` (via `install_market_theme_from_base`/`validate_manifest`) or `market_asset_url` calls `validate_market_path` with a string that is empty, longer than 256 bytes, starts with `/`, contains `\`, or contains `?`, `#`, or `\0` — e.g. absolute paths, Windows-style separators, or URLs with query strings pasted into path fields.

Common situations: Manifest authors pasting full URLs (`assets/img.png?v=2`) into relative path fields; Windows-authored manifests using `assets\skin.png`; leading-slash paths like `/assets/skin.png`; empty `preview` fields for themes without a preview image.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at crates/codex-plus-core/src/dream_skin_market.rs:350

fn market_asset_url(base_url: &str, relative: &str) -> anyhow::Result<String> {
    validate_market_path(relative)?;
    let base = reqwest::Url::parse(base_url).context("主题市场基础地址无效")?;
    let joined = base.join(relative).context("主题市场资源地址无效")?;
    if joined.scheme() != base.scheme() || joined.host_str() != base.host_str() {
        bail!("主题市场资源地址越界");
    }
    Ok(joined.to_string())
}

fn validate_market_path(value: &str) -> anyhow::Result<()> {
    if value.is_empty()
        || value.len() > 256
        || value.starts_with('/')
        || value.contains('\\')
        || value.contains(['?', '#', '\0'])
    {
        bail!("无效的主题市场相对路径");
    }
    for segment in value.split('/') {
        if segment.is_empty()
            || matches!(segment, "." | "..")
            || !segment
                .bytes()
                .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_' | b'.'))
        {
            bail!("无效的主题市场相对路径");
        }
    }
    Ok(())
}

fn valid_theme_id(value: &str) -> bool {
    let bytes = value.as_bytes();
    (1..=64).contains(&bytes.len())
        && bytes[0].is_ascii_alphanumeric()

View on GitHub (pinned to b1ed92e5e4)