siyuan-note/siyuan · error
invalid backgroundColor
Error message
invalid backgroundColor: %w
What it means
Same validation path as the color error, but for the BackgroundColor field of an inline style theme: normalizeInlineStyleTheme wraps the normalizeInlineStyleColor failure for BackgroundColor with "invalid backgroundColor". The value was non-empty yet not a valid normalized color string.
Solutions
- Rewrite the background color as 6-digit hex #RRGGBB (lowercase is applied automatically)
- Clear backgroundColor (empty string) if no background is intended — empty is valid
- Validate the hex pattern before saving from plugins/scripts
Example fix
// before backgroundColor: "rgb(255, 0, 0)" // after backgroundColor: "#ff0000"
Defensive patterns
Strategy: validation
Validate before calling
const HEX6 = /^#[0-9a-fA-F]{6}$/;
function validBackgroundColor(c) { return c === "" || HEX6.test(c.trim()); } Type guard
const isHexColor = v => typeof v === "string" && /^#[0-9a-fA-F]{6}$/.test(v.trim()); Try / catch
try { saveTheme(t); } catch (e) { if (String(e).includes("invalid backgroundColor")) { t.backgroundColor = ""; saveTheme(t); } } Prevention
- Validate backgroundColor with the same #RRGGBB rule as color
- Convert rgb()/rgba() inputs to hex before submitting
- Keep a single shared color-normalization helper for both fields
When it happens
Trigger: Saving an inline style theme whose backgroundColor is a malformed value like "lightblue", "#12345", "rgb(0,0,0)", or contains stray whitespace/uppercase-plus-wrong-length hex.
Common situations: Pasting background colors from CSS or design tools in formats other than #RRGGBB; config migrations that stored old color formats; typos in hex digits.
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
- invalid color
- color [ ] must use #RRGGBB format
- invalid background color
- invalid color [ ]
- invalid dark theme of attribute view custom color
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/9a5ee4213ad65c79.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/inline_style.go:859
if _, exists := seen[id]; exists {
continue
}
seen[id] = struct{}{}
ret = append(ret, id)
}
sort.Slice(ret, func(i, j int) bool {
return builtinStyleOrder[ret[i]] < builtinStyleOrder[ret[j]]
})
return ret, nil
}
func normalizeInlineStyleTheme(theme *InlineStyleTheme) (ret *InlineStyleTheme, err error) {
ret = &InlineStyleTheme{}
if ret.Color, err = normalizeInlineStyleColor(theme.Color); err != nil {
return nil, fmt.Errorf("invalid color: %w", err)
}
if ret.BackgroundColor, err = normalizeInlineStyleColor(theme.BackgroundColor); err != nil {
return nil, fmt.Errorf("invalid backgroundColor: %w", err)
}
return ret, nil
}
func normalizeInlineStyleColor(color string) (ret string, err error) {
ret = strings.ToLower(strings.TrimSpace(color))
if ret == "" {
return ret, nil
}
if !inlineStyleColorPattern.MatchString(ret) {
return "", fmt.Errorf("color [%s] must use #RRGGBB format", color)
}
return ret, nil
}
func init() {
av.LoadWorkspacePalette = loadWorkspaceAVPalette
}View on GitHub (pinned to 9f775e8a12)