siyuan-note/siyuan · error

builtin color index [ ] must be between and

Error message

builtin color index [%d] must be between %d and %d

What it means

Builtin color patches update specific palette slots identified by Index. SetWorkspaceAVPalette requires each patch index to lie between minBuiltinColorIndex and neutralAVColorIndex inclusive; anything outside fails with 'builtin color index [%d] must be between %d and %d'.

Solutions

  1. Clamp/validate patch.Index against the current minBuiltinColorIndex..neutralAVColorIndex range before calling
  2. Refresh the palette definition in the client so indexes match the current builtin color set
  3. Drop patches with out-of-range indexes instead of sending them

Example fix

// before
patches = append(patches, &model.WorkspaceAVBuiltinColorUpdate{Index: idx, Color: c})
// after
if idx >= model.MinBuiltinColorIndex && idx <= model.NeutralAVColorIndex {
    patches = append(patches, &model.WorkspaceAVBuiltinColorUpdate{Index: idx, Color: c})
}
Defensive patterns

Strategy: validation

Validate before calling

if idx < model.MinBuiltinColorIndex || idx > model.NeutralAVColorIndex {
    return fmt.Errorf("builtin color index %d out of range", idx)
}

Prevention

When it happens

Trigger: Calling `SetWorkspaceAVPalette` with a patch whose `Index < minBuiltinColorIndex` or `Index > neutralAVColorIndex`, e.g. a negative index or one beyond the fixed builtin color count.

Common situations: Frontend sends an index from a stale palette layout after the builtin color set changed; a plugin hardcodes an out-of-range index; off-by-one indexing.

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@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/ebe034e5ebb0aa41. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/inline_style.go:194

	inlineStylesLock.Lock()
	defer inlineStylesLock.Unlock()

	if update == nil {
		return nil, false, errors.New("workspace attribute view palette update must not be null")
	}
	current, err := loadInlineStyles()
	if err != nil {
		return nil, false, err
	}
	currentAV := current.AV
	current.AV = &InlineStyleAV{Colors: update.Colors, Order: update.Order}
	updatedIndexes := map[int]struct{}{}
	for _, patch := range update.BuiltinColors {
		if patch == nil {
			return nil, false, errors.New("workspace attribute view builtin color update must not be null")
		}
		if patch.Index < minBuiltinColorIndex || neutralAVColorIndex < patch.Index {
			return nil, false, fmt.Errorf("builtin color index [%d] must be between %d and %d", patch.Index,
				minBuiltinColorIndex, neutralAVColorIndex)
		}
		if _, duplicated := updatedIndexes[patch.Index]; duplicated {
			return nil, false, fmt.Errorf("duplicate workspace attribute view builtin color update [%d]", patch.Index)
		}
		updatedIndexes[patch.Index] = struct{}{}
		filtered := current.Builtin.Colors[:0]
		for _, color := range current.Builtin.Colors {
			if color.Index != patch.Index {
				filtered = append(filtered, color)
			}
		}
		current.Builtin.Colors = filtered
		if patch.Customized {
			current.Builtin.Colors = append(current.Builtin.Colors, &InlineStyleBuiltinColor{
				Index: patch.Index,
				Light: patch.Light,
				Dark:  patch.Dark,

View on GitHub (pinned to 9f775e8a12)