BigPizzaV3/CodexPlusPlus · error

theme.json.colors 字段无效

Error message

theme.json.colors 字段无效

What it means

When theme.json contains a colors object, validate_theme requires it to have exactly the 10 defined color keys (background, panel, panelAlt, accent, accentAlt, secondary, highlight, text, muted, line) — no more, no less. If colors.len() != 10 (an extra, missing, or unknown key), this error is thrown before per-key validation.

Solutions

  1. Make colors contain exactly the 10 keys: background, panel, panelAlt, accent, accentAlt, secondary, highlight, text, muted, line
  2. Remove any extra/custom keys not in the list
  3. Add any missing required color keys
  4. Fix typos in color key names

Example fix

// before
"colors": { "background": "#000", "panel": "#111", "primary": "#0af" }
// after
"colors": { "background":"#0d1117", "panel":"#161b22", "panelAlt":"#1c2128", "accent":"#58a6ff", "accentAlt":"#1f6feb", "secondary":"#8b949e", "highlight":"#f2cc60", "text":"#e6edf3", "muted":"#7d8590", "line":"#30363d" }
Defensive patterns

Strategy: validation

Validate before calling

const COLOR_KEYS = ["background","panel","panelAlt","accent","accentAlt","secondary","highlight","text","muted","line"];
if (theme.colors) {
  const keys = Object.keys(theme.colors);
  if (keys.length !== COLOR_KEYS.length || !COLOR_KEYS.every(k => k in theme.colors)) {
    throw new Error("colors must have exactly the 10 required keys, no extras");
  }
}

Type guard

function hasExactColorKeys(c) {
  const REQ = ["background","panel","panelAlt","accent","accentAlt","secondary","highlight","text","muted","line"];
  return !!c && Object.keys(c).length === REQ.length && REQ.every(k => k in c);
}

Prevention

When it happens

Trigger: Calling validate_and_read_package with a theme.json whose colors object has fewer than 10 keys (missing one of the required colors), more than 10 keys (added a custom color), or unknown/extra keys.

Common situations: Adding a custom "card" or "primary" color key; omitting a rarely used color like muted; copying an older theme format with a different color set; a typo creating a duplicate-meaning key (e.g. "line" vs "lines").

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

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

    if let Some(art) = object.get("art") {
        validate_theme_art(art)?;
    }
    if let Some(colors) = object.get("colors") {
        let colors = colors.as_object().context("theme.json.colors 必须是对象")?;
        let keys = [
            "background",
            "panel",
            "panelAlt",
            "accent",
            "accentAlt",
            "secondary",
            "highlight",
            "text",
            "muted",
            "line",
        ];
        if colors.len() != keys.len() {
            bail!("theme.json.colors 字段无效");
        }
        for key in keys {
            if colors
                .get(key)
                .and_then(Value::as_str)
                .is_none_or(|value| !valid_theme_color(value))
            {
                bail!("theme.json.colors 缺少 {key}");
            }
        }
    }
    Ok(())
}

fn validate_manifest_files(
    manifest: &DreamSkinPackageManifest,
    manifest_bytes: &[u8],
    theme_bytes: &[u8],

View on GitHub (pinned to b1ed92e5e4)