{"record":{"id":"ebe034e5ebb0aa41","repo":"siyuan-note/siyuan","slug":"builtin-color-index-d-must-be-between-d-and-d","errorCode":null,"errorMessage":"builtin color index [%d] must be between %d and %d","messagePattern":"builtin color index \\[(.+?)\\] must be between (.+?) and (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":194,"sourceCode":"\tinlineStylesLock.Lock()\n\tdefer inlineStylesLock.Unlock()\n\n\tif update == nil {\n\t\treturn nil, false, errors.New(\"workspace attribute view palette update must not be null\")\n\t}\n\tcurrent, err := loadInlineStyles()\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n\tcurrentAV := current.AV\n\tcurrent.AV = &InlineStyleAV{Colors: update.Colors, Order: update.Order}\n\tupdatedIndexes := map[int]struct{}{}\n\tfor _, patch := range update.BuiltinColors {\n\t\tif patch == nil {\n\t\t\treturn nil, false, errors.New(\"workspace attribute view builtin color update must not be null\")\n\t\t}\n\t\tif patch.Index < minBuiltinColorIndex || neutralAVColorIndex < patch.Index {\n\t\t\treturn nil, false, fmt.Errorf(\"builtin color index [%d] must be between %d and %d\", patch.Index,\n\t\t\t\tminBuiltinColorIndex, neutralAVColorIndex)\n\t\t}\n\t\tif _, duplicated := updatedIndexes[patch.Index]; duplicated {\n\t\t\treturn nil, false, fmt.Errorf(\"duplicate workspace attribute view builtin color update [%d]\", patch.Index)\n\t\t}\n\t\tupdatedIndexes[patch.Index] = struct{}{}\n\t\tfiltered := current.Builtin.Colors[:0]\n\t\tfor _, color := range current.Builtin.Colors {\n\t\t\tif color.Index != patch.Index {\n\t\t\t\tfiltered = append(filtered, color)\n\t\t\t}\n\t\t}\n\t\tcurrent.Builtin.Colors = filtered\n\t\tif patch.Customized {\n\t\t\tcurrent.Builtin.Colors = append(current.Builtin.Colors, &InlineStyleBuiltinColor{\n\t\t\t\tIndex: patch.Index,\n\t\t\t\tLight: patch.Light,\n\t\t\t\tDark:  patch.Dark,","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L176-L212","documentation":"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'.","triggerScenarios":"Calling `SetWorkspaceAVPalette` with a patch whose `Index < minBuiltinColorIndex` or `Index > neutralAVColorIndex`, e.g. a negative index or one beyond the fixed builtin color count.","commonSituations":"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.","solutions":["Clamp/validate patch.Index against the current minBuiltinColorIndex..neutralAVColorIndex range before calling","Refresh the palette definition in the client so indexes match the current builtin color set","Drop patches with out-of-range indexes instead of sending them"],"exampleFix":"// before\npatches = append(patches, &model.WorkspaceAVBuiltinColorUpdate{Index: idx, Color: c})\n// after\nif idx >= model.MinBuiltinColorIndex && idx <= model.NeutralAVColorIndex {\n    patches = append(patches, &model.WorkspaceAVBuiltinColorUpdate{Index: idx, Color: c})\n}","handlingStrategy":"validation","validationCode":"if idx < model.MinBuiltinColorIndex || idx > model.NeutralAVColorIndex {\n    return fmt.Errorf(\"builtin color index %d out of range\", idx)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep client palette index constants in sync with the kernel","Clamp indexes to the documented range before sending patches","Update plugins after builtin color set changes"],"tags":["value-out-of-range","attribute-view","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}