siyuan-note/siyuan · error

attribute view custom color index [%d] is out of range [%d,

Error message

attribute view custom color index [%d] is out of range [%d, %d]

What it means

normalizeAttributeViewCustomColor rejects colors whose Index falls outside the reserved custom range [CustomColorMinIndex 15, CustomColorMaxIndex 78]. Indexes 0-13 are built-in colors and anything above 78 has no slot, so such entries are invalid custom colors.

Source

Thrown at kernel/av/color.go:132

		indexes[normalized.Index] = struct{}{}
		ret = append(ret, normalized)
	}

	sort.Slice(ret, func(i, j int) bool {
		return ret[i].Index < ret[j].Index
	})
	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))

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Remap the index into the valid range [15, 78], e.g. Index += av.CustomColorMinIndex for 0-based imports.
  2. Allocate new colors with av.NextCustomColorIndex instead of hardcoding indexes.
  3. If the index refers to a built-in color (0-13), model it as a built-in color reference rather than a custom color entry.
  4. Drop entries beyond CustomColorMaxIndex and surface a user-visible notice that part of the palette was ignored.

Example fix

// before
 custom := &av.AttributeViewCustomColor{Index: 0} // collides with built-ins

// after
 custom := &av.AttributeViewCustomColor{Index: av.CustomColorMinIndex} // 15, first custom slot
Defensive patterns

Strategy: validation

Validate before calling

func indexInRange(i int) bool {
	return i >= av.CustomColorMinIndex && i <= av.CustomColorMaxIndex // [15, 78]
}

Try / catch

if _, err := av.NormalizeAttributeViewCustomColors(colors, true); err != nil && strings.Contains(err.Error(), "is out of range") {
	// remap 0-based imports by adding av.CustomColorMinIndex
}

Prevention

When it happens

Trigger: Constructing an AttributeViewCustomColor with Index < 15 or > 78 and passing it to NormalizeAttributeViewCustomColors (via normalizeAttributeViewCustomColor, color.go:131); importing palettes that use 0-based indexing; rendering paths resolving colors via resolveColor with bad stored indexes.

Common situations: A script numbering custom colors from 0 instead of after the 14 built-in colors; a palette from another tool with more than 64 custom slots; off-by-one or byte-overflow corruption in .av JSON.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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