BigPizzaV3/CodexPlusPlus · error
theme.json 的链接或外观字段无效
Error message
theme.json 的链接或外观字段无效
What it means
validate_theme validates two special optional fields together: promoUrl must be a safe string of at most 512 characters, and appearance must be exactly one of "auto", "light", or "dark". If either present field fails these constraints, the library throws this combined error.
Solutions
- Set appearance to exactly "auto", "light", or "dark"
- Shorten promoUrl to 512 characters or fewer and remove unsafe characters
- Ensure both values are plain JSON strings
- Omit either field if not needed — both are optional
Example fix
// before "appearance": "system", "promoUrl": 123 // after "appearance": "auto", "promoUrl": "https://example.com/promo"
Defensive patterns
Strategy: validation
Validate before calling
if ("appearance" in theme && !["auto","light","dark"].includes(theme.appearance)) {
throw new Error("appearance must be auto|light|dark");
}
if ("promoUrl" in theme && (typeof theme.promoUrl !== "string" || theme.promoUrl.length > 512 || /[\u0000-\u001f]/.test(theme.promoUrl))) {
throw new Error("promoUrl must be a safe string of at most 512 chars");
} Type guard
function isAppearance(v) {
return v === "auto" || v === "light" || v === "dark";
} Prevention
- Use a dropdown/enum for appearance (auto|light|dark) in tooling, never free text
- Keep promo URLs short; strip tracking parameters if the URL grows past 512 chars
- Validate the theme JSON schema in CI before packaging
When it happens
Trigger: Calling validate_and_read_package with a theme.json where promoUrl is a non-string or exceeds 512 chars / unsafe text, or appearance is a string other than auto/light/dark (or a non-string).
Common situations: Typing "system" or "default" for appearance instead of "auto"; putting an overly long tracking URL in promoUrl; localizing appearance values (e.g. "自动"); quoting appearance as a number.
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
- theme.json.colors 字段无效
- theme.json.colors 缺少
- theme.json. 无效
- theme.json 与 manifest 身份或背景图不一致
- theme.json.name 无效
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/9c06ebb8f3748d25.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-core/src/dream_skin_package.rs:1051
] {
if object.get(key).is_some_and(|value| {
value
.as_str()
.is_none_or(|text| !safe_manifest_text(text, 0, 120, false))
}) {
bail!("theme.json.{key} 无效");
}
}
if object.get("promoUrl").is_some_and(|value| {
value
.as_str()
.is_none_or(|text| !safe_manifest_text(text, 0, 512, false))
}) || object.get("appearance").is_some_and(|value| {
value
.as_str()
.is_none_or(|appearance| !matches!(appearance, "auto" | "light" | "dark"))
}) {
bail!("theme.json 的链接或外观字段无效");
}
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",
];View on GitHub (pinned to b1ed92e5e4)