BigPizzaV3/CodexPlusPlus · error

theme.css 每条规则必须至少包含一个声明

Error message

theme.css 每条规则必须至少包含一个声明

What it means

After parsing a rule's declarations, parse_safe_css requires at least one non-empty `property: value;` declaration inside the braces; a rule like `[data-ds-part="main"] { }` (or containing only empty fragments between semicolons) bails with 'theme.css 每条规则必须至少包含一个声明'. Empty rules add nothing to the cascade and are treated as malformed input.

Solutions

  1. Delete every rule whose braces contain no declaration
  2. If a rule lost its declarations during sanitization/cleanup, restore at least one valid whitelisted declaration or remove the selector entirely
  3. Validate locally with validate_safe_css before packaging to catch stub rules early

Example fix

// before
[data-ds-part="header"] { }
// after
[data-ds-part="header"] { background-color: var(--ds-theme-color-panel); }
Defensive patterns

Strategy: validation

Validate before calling

fn no_empty_rules(css: &str) -> bool {
    css.split('{').skip(1).filter_map(|rest| rest.split('}').next()).all(|body| !body.is_empty() && body.split(';').any(|d| !d.trim().is_empty()))
}

Try / catch

if let Err(e) = validate_safe_css(&css) {
    if e.to_string().contains("至少包含一个声明") {
        return Err("remove rules with empty bodies".into());
    }
    return Err(e.into());
}

Prevention

When it happens

Trigger: Selector blocks with empty or whitespace-only bodies; bodies containing only stray semicolons (split(';') filters empty fragments); CSS where all declarations were stripped during sanitization (e.g. comments removed leaving nothing).

Common situations: Authors leaving placeholder rules while iterating on a theme; tools that minify out declarations but keep the selector; copy-paste errors leaving `{ }` stubs.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

                || !seen.insert(property)
            {
                bail!("theme.css CSS 属性无效或重复:{property}");
            }
            if value.is_empty()
                || value.chars().count() > 512
                || value.contains(['{', '}', '<', '>', '!', ';'])
                || !validate_property_value(property, value)
            {
                bail!("theme.css 属性值不受 Safe CSS 支持:{property}");
            }
            declarations += 1;
            if declarations > 512 {
                bail!("theme.css 声明数量超过限制");
            }
            rule_declarations.push((property, value));
        }
        if rule_declarations.is_empty() {
            bail!("theme.css 每条规则必须至少包含一个声明");
        }
        parsed.push(SafeCssRule {
            selector,
            part,
            declarations: rule_declarations,
        });
        if parsed.len() > 128 {
            bail!("theme.css 规则数量超过限制");
        }
        rest = &rest[close + 1..];
    }
    if parsed.is_empty() {
        bail!("theme.css 必须至少包含一条规则");
    }
    Ok(parsed)
}

fn forbidden_css_character(character: char) -> bool {

View on GitHub (pinned to b1ed92e5e4)