BigPizzaV3/CodexPlusPlus · error

必须大于 0

Error message

{label}必须大于 0

What it means

parse of a numeric limit field (context window / auto-compact threshold) requires a positive integer. A value of 0 parses as u64 but is rejected with '{label}必须大于 0' because a zero context window or compact threshold is meaningless. Non-numeric input fails earlier with '{label}必须是正整数'.

Solutions

  1. Use a positive integer (e.g. "128000") for the limit
  2. To express 'no limit / unset', remove the field or pass None/empty so the helper returns Ok(None) instead of 0
  3. Update UI validation to reject 0 at input time

Example fix

// before
model_windows.insert("deepseek-v4-pro".into(), "0".into());
// after
model_windows.insert("deepseek-v4-pro".into(), "1000000".into());
Defensive patterns

Strategy: validation

Validate before calling

fn valid_limit(v: &str) -> bool {
    v.trim().parse::<u64>().map(|n| n > 0).unwrap_or(false)
}

Try / catch

match apply_limits(text, limits) {
    Err(e) if e.to_string().contains("必须大于 0") => clear_or_unset_limit_field(e)?,
    other => other?,
}

Prevention

When it happens

Trigger: Calling the limit-parsing helper (used by apply_context_limits_to_config) with a string like "0" or "+0" for a context-window or auto-compact limit.

Common situations: User typed 0 in the per-model context window field intending 'unlimited'; a template exported 0 as a placeholder and it was applied verbatim.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

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

fn validate_auth_json(auth_bytes: &[u8], path: &Path) -> anyhow::Result<()> {
    if auth_bytes.iter().all(|byte| byte.is_ascii_whitespace()) {
        return Ok(());
    }
    serde_json::from_slice::<Value>(auth_bytes)
        .with_context(|| format!("{} 不是有效 JSON", path.display()))?;
    Ok(())
}

fn parse_optional_positive_u64(value: &str, label: &str) -> anyhow::Result<Option<u64>> {
    let trimmed = value.trim();
    if trimmed.is_empty() {
        return Ok(None);
    }
    let parsed = trimmed
        .parse::<u64>()
        .with_context(|| format!("{label}必须是正整数"))?;
    if parsed == 0 {
        anyhow::bail!("{label}必须大于 0");
    }
    Ok(Some(parsed))
}

fn apply_context_limits_to_config(
    config_text: &str,
    context_window: &str,
    auto_compact_limit: &str,
) -> anyhow::Result<String> {
    let mut doc = parse_toml_document(config_text)?;
    if let Some(value) = parse_optional_positive_u64(context_window, "上下文大小")? {
        doc["model_context_window"] = toml_edit::value(value as i64);
    }
    if let Some(value) = parse_optional_positive_u64(auto_compact_limit, "压缩上下文大小")? {
        doc["model_auto_compact_token_limit"] = toml_edit::value(value as i64);
    }
    Ok(normalize_optional_toml(doc))
}

View on GitHub (pinned to b1ed92e5e4)