siyuan-note/siyuan · error

invalid background color [%s]

Error message

invalid background color [%s]

What it means

Same validation as the foreground error, but for the theme's BackgroundColor value in an attribute view color theme. The value must match attributeViewColorPattern after trim/lowercase or the theme is rejected with the original value in the message.

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 8641553a1f)

Solutions

  1. Fix the background color to a valid full hex string (e.g. #1e1e1e)
  2. Re-save the custom color through the UI so normalization is applied at write time
  3. Validate both color fields with the library's pattern before persisting config

Example fix

// before
backgroundColor: "rgba(0, 0, 0, 0.5)"
// after
backgroundColor: "#000000"
Defensive patterns

Strategy: validation

Validate before calling

if (!/^#[0-9a-fA-F]{6}$/.test(theme.backgroundColor)) throw new Error(`invalid background color [${theme.backgroundColor}]`);

Type guard

function isValidBackgroundColor(t) { return typeof t?.backgroundColor === 'string' && /^#[0-9a-f]{6}$/i.test(t.backgroundColor); }

Prevention

When it happens

Trigger: normalizeAttributeViewColorTheme invoked with a theme whose BackgroundColor fails the regex — occurs whenever custom colors are normalized via NormalizeAttributeViewCustomColors or resolveColor.

Common situations: Synced or hand-edited palettes with missing background values, CSS color function strings like rgba(0,0,0,.5), or uppercase/whitespace variants of otherwise-valid hex.

Related errors


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