BigPizzaV3/CodexPlusPlus · error

theme.json.art 枚举值无效

Error message

theme.json.art 枚举值无效

What it means

validate_theme_art enforces the allowed enum strings for theme.json.art.safeArea and theme.json.art.taskMode. safeArea must be one of "left" | "right" | "none"; taskMode must be one of "ambient" | "full" | "off". The library throws this error when either key is present with any other (or non-string) value.

Solutions

  1. Open theme.json and check art.safeArea and art.taskMode values.
  2. Set safeArea to exactly "left", "right", or "none".
  3. Set taskMode to exactly "ambient", "full", or "off".
  4. Fix case and remove quotes issues: values are lowercase strings.
  5. Re-validate the theme.

Example fix

// before
{ "art": { "safeArea": "Top", "taskMode": "auto" } }
// after
{ "art": { "safeArea": "none", "taskMode": "ambient" } }
Defensive patterns

Strategy: validation

Validate before calling

fn art_enums_valid(art: &Value) -> bool {
    let safe = art.get("safeArea").and_then(|v| v.as_str()).map_or(true, |s| matches!(s, "left"|"right"|"none"));
    let task = art.get("taskMode").and_then(|v| v.as_str()).map_or(true, |s| matches!(s, "ambient"|"full"|"off"));
    safe && task
}

Type guard

fn is_valid_safe_area(v: &Value) -> bool {
    matches!(v.as_str(), Some("left") | Some("right") | Some("none"))
}

Try / catch

match validate_theme(value) {
    Err(e) if e.to_string().contains("枚举值无效") => eprintln!("art.safeArea/taskMode must use allowed enum strings: {e}"),
    other => other?,
}

Prevention

When it happens

Trigger: Calling validate_theme where theme.json.art.safeArea is not exactly "left"/"right"/"none" (e.g. "top", "Left", 1), or theme.json.art.taskMode is not exactly "ambient"/"full"/"off" (e.g. "auto", true).

Common situations: Case mismatches ("Left"); inventing values not in the spec ("top", "center"); using numbers/booleans instead of strings; copying values from a different skin format with different enums.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at crates/codex-plus-core/src/dream_skin_package.rs:1306

    for key in ["focusX", "focusY"] {
        if object.get(key).is_some_and(|value| {
            value
                .as_f64()
                .is_none_or(|number| !number.is_finite() || !(0.0..=1.0).contains(&number))
        }) {
            bail!("theme.json.art.{key} 无效");
        }
    }
    if object.get("safeArea").is_some_and(|value| {
        value
            .as_str()
            .is_none_or(|value| !matches!(value, "left" | "right" | "none"))
    }) || object.get("taskMode").is_some_and(|value| {
        value
            .as_str()
            .is_none_or(|value| !matches!(value, "ambient" | "full" | "off"))
    }) {
        bail!("theme.json.art 枚举值无效");
    }
    Ok(())
}

fn valid_theme_color(value: &str) -> bool {
    if let Some(hex) = value.strip_prefix('#') {
        return matches!(hex.len(), 3 | 4 | 6 | 8)
            && hex.bytes().all(|byte| byte.is_ascii_hexdigit());
    }
    if value.starts_with("rgb(") && value.ends_with(')') {
        let values = &value[4..value.len() - 1];
        return split_top_level(values, ',').is_some_and(|values| {
            values.len() == 3
                && values.into_iter().all(|value| {
                    let value = value.trim();
                    !value.is_empty()
                        && value.len() <= 3
                        && value.bytes().all(|byte| byte.is_ascii_digit())

View on GitHub (pinned to b1ed92e5e4)