BigPizzaV3/CodexPlusPlus · error
theme.css 只能选择 Skin API 注册的 data-ds-part
Error message
theme.css 只能选择 Skin API 注册的 data-ds-part
What it means
Safe CSS only allows selectors of the exact form [data-ds-part="NAME"] targeting parts registered by the Skin API. parse_safe_css requires every selector to literally start with the prefix `[data-ds-part="` ; if it does not, it bails with 'theme.css 只能选择 Skin API 注册的 data-ds-part'. Class, id, element or attribute selectors of any other shape are rejected before the part whitelist is even consulted.
Solutions
- Rewrite every selector to exactly `[data-ds-part="<registered-part>"] { ... }` with double quotes
- Ensure the selector starts at the beginning of the rule — no leading combinators, elements or classes
- Target descendant styling only via the dedicated parts (root, sidebar, main, header, home, home-hero, project-list, thread, message, composer, composer-toolbar, dialog)
Example fix
// before
.sidebar { background-color: #222; }
// after
[data-ds-part="sidebar"] { background-color: #222222; } Defensive patterns
Strategy: validation
Validate before calling
fn selectors_are_ds_part_only(css: &str) -> bool {
css.split('{').filter(|s| !s.contains('}')).all(|sel| {
let sel = sel.trim();
sel.starts_with("[data-ds-part=\"") && sel.ends_with("]")
})
} Try / catch
if let Err(e) = validate_safe_css(&css) {
if e.to_string().contains("data-ds-part") {
return Err("rewrite selectors to the exact form [data-ds-part=\"part\"]".into());
}
return Err(e.into());
} Prevention
- Only ever emit selectors of the form [data-ds-part="name"] with double quotes
- Do not attempt element/class/id selectors — the renderer only applies rules via data-ds-part attributes
- Test each rule against the Skin API part registry before packaging
When it happens
Trigger: Selecting with `body {`, `.sidebar {`, `#root {`, `[data-ds-part='main']` (single quotes), or `[data-ds-part="main"] .child` — anything that does not begin with the exact `[data-ds-part="` prefix.
Common situations: Theme authors writing regular CSS out of habit; converting an existing web theme into a Dream Skin package without rewriting selectors; examples copied from generic CSS docs.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- theme.css 使用了未注册的 Skin API part 或状态
- theme.css 包含不允许的控制字符、注释或转义
- theme.css 为空或超过 256 KiB 限制
- theme.css 必须至少包含一条规则
- theme.css 规则数量超过限制
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/529277afd2b4f7b4.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-core/src/dream_skin_package.rs:329
let open = rest.find('{').context("theme.css 规则缺少开始括号")?;
let selector = rest[..open].trim();
if selector.is_empty()
|| selector.contains([',', '@', ';', '}'])
|| rest[open + 1..].find('{').is_some_and(|nested| {
rest[open + 1..]
.find('}')
.is_none_or(|close| nested < close)
})
{
bail!("theme.css 选择器或规则语法无效");
}
let close = open
+ 1
+ rest[open + 1..]
.find('}')
.context("theme.css 规则缺少结束括号")?;
let Some(after_prefix) = selector.strip_prefix("[data-ds-part=\"") else {
bail!("theme.css 只能选择 Skin API 注册的 data-ds-part");
};
let (part, suffix) = after_prefix
.split_once("\"]")
.context("theme.css data-ds-part 语法无效")?;
if !allowed_parts.contains(&part)
|| (!suffix.is_empty() && suffix != ":hover" && suffix != ":focus-visible")
{
bail!("theme.css 使用了未注册的 Skin API part 或状态");
}
let mut rule_declarations = Vec::new();
let mut seen = HashSet::new();
for declaration in rest[open + 1..close]
.split(';')
.map(str::trim)
.filter(|value| !value.is_empty())
{
let (property, value) = declarationView on GitHub (pinned to b1ed92e5e4)