siyuan-note/siyuan · error
invalid color
Error message
invalid color: %w
What it means
normalizeInlineStyleTheme validates a theme's Color via normalizeInlineStyleColor and wraps any failure with "invalid color". This means the color string supplied for the light or dark variant failed normalization — it was non-empty but not a well-formed color value (e.g. not #RRGGBB).
Solutions
- Convert the value to 6-digit hex form like #RRGGBB (e.g. red -> #ff0000, #fff -> #ffffff)
- Convert rgb()/rgba() values to hex before saving, or clear the field to an empty string to remove the color
- Validate with a regex ^#[0-9a-fA-F]{6}$ in client code before submitting
Example fix
// before color: "#fff" // after color: "#ffffff"
Defensive patterns
Strategy: validation
Validate before calling
const HEX6 = /^#[0-9a-fA-F]{6}$/;
function validColor(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 color")) { t.color = ""; saveTheme(t); } } Prevention
- Normalize all colors to #RRGGBB at input time
- Reject CSS names, rgb(), and 3-digit hex in your form validation
- Use empty string to represent 'no color'
When it happens
Trigger: Saving an inline style theme (light or dark variant) whose color field is a malformed value such as "red", "#fff", "ff0000", or "#GGHHII"; the underlying normalizeInlineStyleColor error is wrapped and surfaced with this message.
Common situations: Hand-editing theme config with CSS color names or 3-digit hex; copying colors from design tools that emit rgb() or 8-digit hex; plugin code building color strings without validation.
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 backgroundColor
- 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/0755ac7091f72bee.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/inline_style.go:856
if _, valid := builtinStyleOrder[id]; !valid {
return nil, fmt.Errorf("invalid hidden builtin style ID [%s]", id)
}
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
}
View on GitHub (pinned to 9f775e8a12)