siyuan-note/siyuan · error
invalid foreground color
Error message
invalid foreground color [%s]
What it means
normalizeAttributeViewColorTheme requires the theme's foreground Color to match attributeViewColorPattern (hex color form) after lowercasing and trimming. Non-matching values are rejected with this error quoting the original input.
Solutions
- Convert the color to #rgb or #rrggbb hex form before saving
- Use a color picker that emits hex values
- Check the pattern in kernel/av/color.go to confirm the accepted format
Example fix
// before
Theme{Color: "rgb(255, 0, 0)"}
// after
Theme{Color: "#ff0000"} Defensive patterns
Strategy: validation
Validate before calling
var colorRe = regexp.MustCompile(`^#[0-9a-f]{3}([0-9a-f]{3})?$`)
func validHex(s string) bool { return colorRe.MatchString(strings.ToLower(strings.TrimSpace(s))) } Try / catch
if _, err := av.NormalizeAttributeViewCustomColors(colors, true); err != nil {
if strings.Contains(err.Error(), "invalid foreground color") { convertToHex(colors) }
} Prevention
- Use color pickers that emit hex strings
- Convert CSS names and rgb() notation to hex upstream
- Trim and lowercase before validating to match kernel normalization
When it happens
Trigger: Calling normalizeAttributeViewCustomColor (directly or via NormalizeAttributeViewCustomColors/resolveColor) with theme.Color like "", "red", "rgb(255,0,0)", or a malformed hex string.
Common situations: CSS color names or functional notations pasted into palette settings; truncated hex values; locale-dependent input with stray whitespace (whitespace is trimmed, but the value must still be 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 background color
- color [ ] must use #RRGGBB format
- invalid backgroundColor
- 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/93228dffc6f4efd3.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/av/color.go:152
}
ret = &AttributeViewCustomColor{Index: color.Index, Hidden: color.Hidden}
ret.Light, err = normalizeAttributeViewColorTheme(color.Light)
if nil != err {
return nil, fmt.Errorf("invalid light theme of attribute view custom color [%d]: %w", color.Index, err)
}
ret.Dark, err = normalizeAttributeViewColorTheme(color.Dark)
if nil != err {
return nil, fmt.Errorf("invalid dark theme of attribute view custom color [%d]: %w", color.Index, err)
}
return
}
func normalizeAttributeViewColorTheme(theme AttributeViewColorTheme) (ret AttributeViewColorTheme, err error) {
ret.Color = strings.ToLower(strings.TrimSpace(theme.Color))
ret.BackgroundColor = strings.ToLower(strings.TrimSpace(theme.BackgroundColor))
if !attributeViewColorPattern.MatchString(ret.Color) {
return AttributeViewColorTheme{}, fmt.Errorf("invalid foreground color [%s]", theme.Color)
}
if !attributeViewColorPattern.MatchString(ret.BackgroundColor) {
return AttributeViewColorTheme{}, fmt.Errorf("invalid background color [%s]", theme.BackgroundColor)
}
return
}
// WorkspacePalette 返回当前工作空间的数据库自定义色和混排顺序。
func WorkspacePalette() (colors []*AttributeViewCustomColor, order []string) {
if LoadWorkspacePalette != nil {
colors, order = LoadWorkspacePalette()
}
if nil == colors {
colors = []*AttributeViewCustomColor{}
}
order = NormalizeAttributeViewColorOrder(order, colors)
return
}View on GitHub (pinned to 9f775e8a12)