siyuan-note/siyuan · error

invalid light theme of attribute view custom color [%d]: %w

Error message

invalid light theme of attribute view custom color [%d]: %w

What it means

Wraps a failure from normalizeAttributeViewColorTheme for the LIGHT theme variant of a custom color. The theme color string failed validation (wrong format or value), and the wrapper records which color index and which theme (light) was at fault using %w so the cause stays unwrappable.

Source

Thrown at kernel/av/color.go:139

	if nil == ret {
		ret = []*AttributeViewCustomColor{}
	}
	return
}

func normalizeAttributeViewCustomColor(color *AttributeViewCustomColor) (ret *AttributeViewCustomColor, err error) {
	if nil == color {
		return nil, errors.New("attribute view custom color must not be null")
	}
	if color.Index < CustomColorMinIndex || CustomColorMaxIndex < color.Index {
		return nil, fmt.Errorf("attribute view custom color index [%d] is out of range [%d, %d]",
			color.Index, CustomColorMinIndex, CustomColorMaxIndex)
	}

	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

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Unwrap the %w cause in the message to see the exact theme-color rule violated, then correct color.Light to the expected format.
  2. Use valid CSS color values accepted by normalizeAttributeViewColorTheme (e.g. var(--b3-*) variables or supported color formats).
  3. Re-copy the color from a working configuration or regenerate it via the attribute view UI instead of hand-editing.
  4. Validate both Light and Dark values with the same normalizer before persisting custom colors.

Example fix

// before
Light: "#abc" // or malformed string rejected by the theme normalizer

// after
Light: "var(--b3-font-color6)" // valid theme color reference
Defensive patterns

Strategy: validation

Validate before calling

func themeColorValid(s string) bool {
	// must satisfy normalizeAttributeViewColorTheme, e.g. var(--b3-...) or accepted hex
	return s != "" && (strings.HasPrefix(s, "var(--b3-") || isSupportedHex(s))
}

Try / catch

if _, err := av.NormalizeAttributeViewCustomColors(colors, true); err != nil && strings.Contains(err.Error(), "invalid light theme") {
	var wrapped error
	errors.As(err, &wrapped) // unwrap %w cause for the exact rule violated
}

Prevention

When it happens

Trigger: normalizeAttributeViewCustomColor at color.go:139 when color.Light fails theme normalization; stored custom color Light values that are not valid theme color strings (e.g. missing var(--b3-...) format, unsupported hex, empty string where a color is required).

Common situations: Hand-edited .av JSON with a malformed light-theme color; a palette importer writing hex colors where the kernel expects CSS variables or a specific format; truncation/corruption of the color string during sync.

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@8641553a1f (2026-09-11). Data as JSON: /api/errors/32bccc1cdc046c74. Report an issue: GitHub.