siyuan-note/siyuan · error
invalid color: %w
Error message
invalid color: %w
What it means
When normalizing an inline style theme (normalizeInlineStyleTheme), the Color field is passed through normalizeInlineStyleColor. If that lower-level validation fails (e.g. bad format, non-empty garbage), the error is wrapped as "invalid color: %w" and the whole theme is rejected. It is the color-specific half of theme validation; backgroundColor failures get their own wrapper.
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 8641553a1f)
Solutions
- Convert the color to a full 6-digit lowercase hex form (#RRGGBB) before saving the theme.
- Expand shorthand #RGB to #RRGGBB or convert named/rgb() colors with a helper before calling the API.
- Read the wrapped inner error (%w) to see the exact underlying reason and fix that value.
Example fix
// before theme.Color = "#abc" // shorthand, rejected // after theme.Color = "#aabbcc" // full 6-digit hex
Defensive patterns
Strategy: validation
Validate before calling
function isValidThemeColor(c) {
return c === "" || /^#[0-9a-fA-F]{6}$/.test(c);
} Prevention
- Normalize any color input (named, rgb(), #RGB) to #RRGGBB before saving.
- Run the regex check on both Color and BackgroundColor before calling the API.
- Prefer a color picker component that outputs 6-digit hex.
When it happens
Trigger: Saving an inline style theme whose light or dark half has a Color value that fails normalizeInlineStyleColor in kernel/model/inline_style.go — e.g. "red", "#fff", "ff0000", "#GGHHII", or a value with unsupported characters.
Common situations: Color pickers emitting rgb() or named colors instead of hex; truncated 3-digit hex codes; users typing colors into a config field; JavaScript theme generation producing uppercase or shorthand hex.
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: %w
- invalid light theme of inline style [%s]: %w
- invalid dark theme of inline style [%s]: %w
- %s must use the same fields in light and dark themes
- hidden builtin %s index [%d] must be between %d and %d
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/0755ac7091f72bee.
Report an issue: GitHub.