siyuan-note/siyuan · error
must define color or backgroundColor
Error message
%s must define color or backgroundColor
What it means
After validating both themes, the normalizer requires each entry to actually define something: at least one of color or backgroundColor must be non-empty, and both themes must use the same field(s). A theme pair that is entirely empty, or that sets only color in light but only backgroundColor in dark, is rejected so light/dark rendering stays consistent.
Solutions
- Fill in at least one of color or backgroundColor in BOTH light and dark for the entry
- Use the same field set in both themes (if light has color+backgroundColor, dark must too)
- Remove entries that are intentionally empty instead of keeping empty shells
- Reload the workspace and verify the style renders in both themes
Example fix
// before
"light": {"color": "#7a5c00"}, "dark": {"backgroundColor": "#4d3a00"}
// after
"light": {"color": "#7a5c00", "backgroundColor": "#fff3b8"}, "dark": {"color": "#ffd66e", "backgroundColor": "#4d3a00"} Defensive patterns
Strategy: validation
Validate before calling
for (const entry of [...(cfg.builtin?.colors ?? []), ...(cfg.builtin?.styles ?? [])]) {
const fields = t => ['color', 'backgroundColor'].filter(f => t?.[f]);
const lf = fields(entry.light), df = fields(entry.dark);
if (lf.length === 0) throw new Error(`${entry.id ?? entry.index} must define color or backgroundColor`);
if (lf.join() !== df.join()) throw new Error(`${entry.id ?? entry.index} must use the same fields in light and dark themes`);
} Type guard
function isConsistentThemePair(e) {
const f = t => ['color', 'backgroundColor'].filter(k => t?.[k]);
return f(e.light).length > 0 && f(e.light).join() === f(e.dark).join();
} Try / catch
if _, err := setInlineStylesData(styles, currentAV); err != nil {
if strings.Contains(err.Error(), "must define color or backgroundColor") || strings.Contains(err.Error(), "must use the same fields") { /* fill/mirror fields and retry */ }
return err
} Prevention
- Never commit empty theme shells — fill color or backgroundColor in both themes
- Mirror field usage between light and dark: if light sets backgroundColor, dark must too
- When adding a field to one theme, add it to the other in the same edit
- Keep a small linter over inline-styles.json covering emptiness and field parity
When it happens
Trigger: A builtin (or validated user) entry in inline-styles.json has light and dark objects whose color/backgroundColor are all empty strings, or light uses {color} while dark uses {backgroundColor}.
Common situations: Creating a placeholder entry intending to fill colors later; copying theme skeletons without values; editing one theme to add a field without updating the other; a generator emitting empty theme objects.
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
- builtin color must not be null
- builtin style must not be null
- duplicate builtin color index
- duplicate builtin style ID
- invalid builtin style ID
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/803fcfdba2bdeff0.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/inline_style.go:804
ret.Order = av.NormalizeAttributeViewColorOrder(palette.Order, colors)
return ret, nil
}
func normalizeInlineStyleThemePair(light, dark *InlineStyleTheme, description string) (normalizedLight,
normalizedDark *InlineStyleTheme, err error) {
if light == nil || dark == nil {
return nil, nil, fmt.Errorf("%s must define light and dark themes", description)
}
if normalizedLight, err = normalizeInlineStyleTheme(light); err != nil {
return nil, nil, fmt.Errorf("invalid light theme of %s: %w", description, err)
}
if normalizedDark, err = normalizeInlineStyleTheme(dark); err != nil {
return nil, nil, fmt.Errorf("invalid dark theme of %s: %w", description, err)
}
lightColor, lightBackground := normalizedLight.Color != "", normalizedLight.BackgroundColor != ""
darkColor, darkBackground := normalizedDark.Color != "", normalizedDark.BackgroundColor != ""
if !lightColor && !lightBackground {
return nil, nil, fmt.Errorf("%s must define color or backgroundColor", description)
}
if lightColor != darkColor || lightBackground != darkBackground {
return nil, nil, fmt.Errorf("%s must use the same fields in light and dark themes", description)
}
return normalizedLight, normalizedDark, nil
}
func normalizeHiddenBuiltinColorIndexes(indexes []int, field string) (ret []int, err error) {
ret = make([]int, 0, len(indexes))
seen := make(map[int]struct{}, len(indexes))
maxIndex := maxBuiltinColorIndex
if field == "av" {
maxIndex = neutralAVColorIndex
}
for _, index := range indexes {
if index < minBuiltinColorIndex || maxIndex < index {
return nil, fmt.Errorf("hidden builtin %s index [%d] must be between %d and %d", field, index,
minBuiltinColorIndex, maxIndex)View on GitHub (pinned to 9f775e8a12)