BigPizzaV3/CodexPlusPlus · error

theme.css 为空或超过 256 KiB 限制

Error message

theme.css 为空或超过 256 KiB 限制

What it means

parse_safe_css (used by validate_safe_css and compile_safe_css) first requires theme.css to be non-empty and at most CSS_LIMIT = 262144 bytes (256 KiB, measured with str::len, i.e. UTF-8 bytes). An empty stylesheet carries no rules and an oversized one would let a package push huge payloads into the renderer, so both are rejected outright with 'theme.css 为空或超过 256 KiB 限制'.

Solutions

  1. Check the file: `wc -c theme.css` — if 0, write real rules; if > 262144, trim it
  2. Split or minify the CSS: remove redundant rules, merge selectors for the same [data-ds-part], drop unused declarations
  3. Keep only the whitelisted properties (colors, borders, box-shadow, fonts, transitions, backdrop-filter) — arbitrary resets are rejected anyway, so deleting them loses nothing

Example fix

// before
$ wc -c theme.css  # 300000
// after
# strip rules not targeting [data-ds-part=...] and re-check
$ wc -c theme.css  # 24000
Defensive patterns

Strategy: validation

Validate before calling

fn css_size_ok(css: &str) -> bool {
    !css.is_empty() && css.len() <= 256 * 1024
}

Type guard

fn is_non_empty_css(input: Option<&str>) -> bool {
    input.map_or(false, |css| !css.trim().is_empty() && css.len() <= 262_144)
}

Try / catch

match validate_safe_css(&css) {
    Ok(()) => {},
    Err(e) if e.to_string().contains("256 KiB") => return Err("theme.css is empty or exceeds 256 KiB".into()),
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: validate_safe_css("") or compile_safe_css with an empty string; any theme.css whose byte length exceeds 262144, even if the extra bytes are whitespace or comments; a zip entry read produced empty css_bytes in validate_and_read_package (though that usually fails earlier with '超过大小限制').

Common situations: Theme authors accidentally shipping a zero-byte theme.css after an editor mishap; hand-written CSS that grew past 256 KiB with copied-in reset sheets or huge font stacks; build tooling emitting an empty file when a template fails to render.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


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

Appendix: source

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

            compiled.push_str(rule.selector);
            compiled.push_str(" :where(button:not([class~=\"bg-token-foreground\"]), button:not([class~=\"bg-token-foreground\"]) *) {\n");
            compiled.push_str(&format!("    color: {value} !important;\n  }}\n"));
        }
    }
    compiled.push_str("}\n");
    Ok(compiled)
}

#[derive(Debug)]
struct SafeCssRule<'a> {
    selector: &'a str,
    part: &'a str,
    declarations: Vec<(&'a str, &'a str)>,
}

fn parse_safe_css(css: &str) -> anyhow::Result<Vec<SafeCssRule<'_>>> {
    if css.is_empty() || css.len() > CSS_LIMIT {
        bail!("theme.css 为空或超过 256 KiB 限制");
    }
    if css.chars().any(forbidden_css_character)
        || css.contains("/*")
        || css.contains("*/")
        || css.contains('\\')
    {
        bail!("theme.css 包含不允许的控制字符、注释或转义");
    }
    let allowed_parts = [
        "root",
        "sidebar",
        "main",
        "header",
        "home",
        "home-hero",
        "project-list",
        "thread",
        "message",

View on GitHub (pinned to b1ed92e5e4)