siyuan-note/siyuan · error

invalid background color

Error message

invalid background color [%s]

What it means

Identical validation to the foreground color, applied to the theme's BackgroundColor: it must match attributeViewColorPattern after lowercasing and trimming, otherwise the theme is rejected with this error quoting the original input.

Solutions

  1. Convert the background color to valid #rgb/#rrggbb hex
  2. Remove the placeholder value and pick a concrete hex color
  3. Validate both Color and BackgroundColor with the same regex before persisting

Example fix

// before
Theme{Color: "#ffffff", BackgroundColor: "transparent"}
// after
Theme{Color: "#ffffff", BackgroundColor: "#000000"}
Defensive patterns

Strategy: validation

Validate before calling

var colorRe = regexp.MustCompile(`^#[0-9a-f]{3}([0-9a-f]{3})?$`)
if !colorRe.MatchString(strings.ToLower(strings.TrimSpace(theme.BackgroundColor))) { return err }

Try / catch

if _, err := av.NormalizeAttributeViewCustomColors(colors, true); err != nil {
    if strings.Contains(err.Error(), "invalid background color") { setFallbackBackground(colors) }
}

Prevention

When it happens

Trigger: Calling normalizeAttributeViewCustomColor with theme.BackgroundColor set to a non-hex value (empty string, CSS name, rgb() notation, malformed hex).

Common situations: Background color left as "transparent" or "none" (not accepted); only the foreground was updated and the background kept an old placeholder; third-party theme exports using non-hex notation.

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


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/ad23240e7c535ce3. Report an issue: GitHub.

Appendix: source

Thrown at kernel/av/color.go:155

	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
}

// DefaultAttributeViewColorOrder 返回内置色在前、自定义色按编号排列的默认顺序。
func DefaultAttributeViewColorOrder(colors []*AttributeViewCustomColor) []string {

View on GitHub (pinned to 9f775e8a12)