{"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/8641553a1f07374001902d3ce773285db1292b2d/kernel/av/color.go#L114-L150","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remap the index into the valid range [15, 78], e.g. Index += av.CustomColorMinIndex for 0-based imports.","Allocate new colors with av.NextCustomColorIndex instead of hardcoding indexes.","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.","Drop entries beyond CustomColorMaxIndex and surface a user-visible notice that part of the palette was ignored."],"exampleFix":"// before\n custom := &av.AttributeViewCustomColor{Index: 0} // collides with built-ins\n\n// after\n custom := &av.AttributeViewCustomColor{Index: av.CustomColorMinIndex} // 15, first custom slot","handlingStrategy":"validation","validationCode":"func indexInRange(i int) bool {\n\treturn i >= av.CustomColorMinIndex && i <= av.CustomColorMaxIndex // [15, 78]\n}","typeGuard":null,"tryCatchPattern":"if _, err := av.NormalizeAttributeViewCustomColors(colors, true); err != nil && strings.Contains(err.Error(), \"is out of range\") {\n\t// remap 0-based imports by adding av.CustomColorMinIndex\n}","preventionTips":["Number custom colors starting at av.CustomColorMinIndex (15), never 0","Allocate new slots with av.NextCustomColorIndex","Model built-in colors (0-13) separately from custom colors"],"tags":["attribute-view","custom-color","value-out-of-range","validation","siyuan-kernel"],"backgroundTag":"value-out-of-range","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}