{"record":{"id":"4439c80efa9ac9d9","repo":"siyuan-note/siyuan","slug":"attribute-view-custom-color-index-d-is-out-of-r","errorCode":null,"errorMessage":"attribute view custom color index [%d] is out of range [%d, %d]","messagePattern":"attribute view custom color index \\[(.+?)\\] is out of range \\[(.+?), (.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/color.go","lineNumber":132,"sourceCode":"\t\tindexes[normalized.Index] = struct{}{}\n\t\tret = append(ret, normalized)\n\t}\n\n\tsort.Slice(ret, func(i, j int) bool {\n\t\treturn ret[i].Index < ret[j].Index\n\t})\n\tif nil == ret {\n\t\tret = []*AttributeViewCustomColor{}\n\t}\n\treturn\n}\n\nfunc normalizeAttributeViewCustomColor(color *AttributeViewCustomColor) (ret *AttributeViewCustomColor, err error) {\n\tif nil == color {\n\t\treturn nil, errors.New(\"attribute view custom color must not be null\")\n\t}\n\tif color.Index < CustomColorMinIndex || CustomColorMaxIndex < color.Index {\n\t\treturn nil, fmt.Errorf(\"attribute view custom color index [%d] is out of range [%d, %d]\",\n\t\t\tcolor.Index, CustomColorMinIndex, CustomColorMaxIndex)\n\t}\n\n\tret = &AttributeViewCustomColor{Index: color.Index, Hidden: color.Hidden}\n\tret.Light, err = normalizeAttributeViewColorTheme(color.Light)\n\tif nil != err {\n\t\treturn nil, fmt.Errorf(\"invalid light theme of attribute view custom color [%d]: %w\", color.Index, err)\n\t}\n\tret.Dark, err = normalizeAttributeViewColorTheme(color.Dark)\n\tif nil != err {\n\t\treturn nil, fmt.Errorf(\"invalid dark theme of attribute view custom color [%d]: %w\", color.Index, err)\n\t}\n\treturn\n}\n\nfunc normalizeAttributeViewColorTheme(theme AttributeViewColorTheme) (ret AttributeViewColorTheme, err error) {\n\tret.Color = strings.ToLower(strings.TrimSpace(theme.Color))\n\tret.BackgroundColor = strings.ToLower(strings.TrimSpace(theme.BackgroundColor))","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/color.go#L114-L150","documentation":"normalizeAttributeViewCustomColor validates that each custom color's Index lies within the inclusive range [CustomColorMinIndex, CustomColorMaxIndex]. An index outside this range cannot be represented in the palette and is rejected with this error naming the offending index and the allowed bounds.","triggerScenarios":"Calling NormalizeAttributeViewCustomColors (or resolveColor indirectly) with a color whose Index is negative or greater than CustomColorMaxIndex — commonly from hand-edited palette JSON, imported configs, or an off-by-one index counter.","commonSituations":"Copying an entry and doubling its index; migrating palettes from older versions with different bounds; plugin code computing index from list length that starts at 1 instead of 0 (or vice versa).","solutions":["Clamp or reassign the index to a value within [CustomColorMinIndex, CustomColorMaxIndex]","Renumber all colors sequentially in-range after import/merge","Check the constants in kernel/av/color.go for the current valid range"],"exampleFix":"// before\ncolors = append(colors, &av.AttributeViewCustomColor{Index: 99, Light: l, Dark: d})\n// after\ncolors = append(colors, &av.AttributeViewCustomColor{Index: av.CustomColorMaxIndex, Light: l, Dark: d})","handlingStrategy":"validation","validationCode":"if c.Index < av.CustomColorMinIndex || av.CustomColorMaxIndex < c.Index {\n    return fmt.Errorf(\"index %d out of range\", c.Index)\n}","typeGuard":null,"tryCatchPattern":"if _, err := av.NormalizeAttributeViewCustomColors(colors, true); err != nil {\n    if strings.Contains(err.Error(), \"is out of range\") { renumber(colors) }\n}","preventionTips":["Assign indexes from av.CustomColorMinIndex..av.CustomColorMaxIndex only","Clamp imported indexes to the valid range","Read the constants from kernel/av/color.go rather than hardcoding bounds"],"tags":["attribute-view","range","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"}