siyuan-note/siyuan · error

invalid dark theme of attribute view custom color

Error message

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

What it means

Same validation as the light theme, but for the Dark theme variant of a custom color: if normalizeAttributeViewColorTheme fails on color.Dark, the cause is wrapped with this message identifying the color index. The wrapped cause names the specific offending field.

Solutions

  1. Set Dark.Color and Dark.BackgroundColor to valid hex values matching the pattern
  2. If only one theme matters, copy the validated Light theme into Dark
  3. Inspect the wrapped cause to see which field (foreground/background) failed

Example fix

// before
Dark: av.AttributeViewColorTheme{Color: ""}
// after
Dark: av.AttributeViewColorTheme{Color: "#111111", 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(c.Dark.Color))) { return err }

Try / catch

if _, err := av.NormalizeAttributeViewCustomColors(colors, true); err != nil {
    if strings.Contains(err.Error(), "invalid dark theme") { copyValidLightToDark(colors) }
}

Prevention

When it happens

Trigger: Calling NormalizeAttributeViewCustomColors with a color whose Dark.Color or Dark.BackgroundColor fails the attributeViewColorPattern check after trim/lowercase normalization.

Common situations: Dark theme colors left empty or as placeholder text; palettes copied from tools that only export one theme and leave Dark with an invalid default; typos in hand-edited dark hex values.

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/f7e35a717403fd9b. Report an issue: GitHub.

Appendix: source

Thrown at kernel/av/color.go:143

}

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
}

// WorkspacePalette 返回当前工作空间的数据库自定义色和混排顺序。
func WorkspacePalette() (colors []*AttributeViewCustomColor, order []string) {

View on GitHub (pinned to 9f775e8a12)