{"record":{"id":"d58892a4d5909f85","repo":"siyuan-note/siyuan","slug":"attribute-view-custom-colors-count-exceeds-the-d","errorCode":null,"errorMessage":"attribute view custom colors count exceeds the %d item limit","messagePattern":"attribute view custom colors count exceeds the (.+?) item limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/color.go","lineNumber":96,"sourceCode":"// UnmarshalJSON 忽略外部输入中的派生颜色，派生颜色只能由内核根据数据库调色板生成。\nfunc (value *ValueSelect) UnmarshalJSON(data []byte) error {\n\tdecoded := struct {\n\t\tContent string `json:\"content\"`\n\t\tColor   string `json:\"color\"`\n\t}{}\n\tif err := json.Unmarshal(data, &decoded); nil != err {\n\t\treturn err\n\t}\n\tvalue.Content = decoded.Content\n\tvalue.Color = decoded.Color\n\tvalue.ResolvedColor = nil\n\treturn nil\n}\n\n// NormalizeAttributeViewCustomColors 校验并规范化数据库自定义颜色。\nfunc NormalizeAttributeViewCustomColors(colors []*AttributeViewCustomColor, strict bool) (ret []*AttributeViewCustomColor, err error) {\n\tif strict && MaxCustomColors < len(colors) {\n\t\treturn nil, fmt.Errorf(\"attribute view custom colors count exceeds the %d item limit\", MaxCustomColors)\n\t}\n\n\tindexes := map[int]struct{}{}\n\tfor _, color := range colors {\n\t\tnormalized, normalizeErr := normalizeAttributeViewCustomColor(color)\n\t\tif nil != normalizeErr {\n\t\t\tif strict {\n\t\t\t\treturn nil, normalizeErr\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tif _, ok := indexes[normalized.Index]; ok {\n\t\t\tif strict {\n\t\t\t\treturn nil, fmt.Errorf(\"duplicated attribute view custom color index [%d]\", normalized.Index)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tindexes[normalized.Index] = struct{}{}","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/color.go#L78-L114","documentation":"NormalizeAttributeViewCustomColors validates and normalizes a database (attribute view) custom color list. In strict mode, if the input list contains more than MaxCustomColors entries, it rejects the entire list rather than truncating. This protects the persisted palette configuration from silently growing beyond the supported limit.","triggerScenarios":"Calling setAttrViewCustomColors, customColorPalette, or decodeHistoricalWorkspacePalette with a palette whose length exceeds MaxCustomColors while strict=true; decoding a workspace palette file that was hand-edited or produced by an older/newer version without the cap.","commonSituations":"Hand-editing the workspace palette JSON and adding too many colors; importing palette settings from another workspace or version that did not enforce the limit; plugin code appending custom colors without checking MaxCustomColors.","solutions":["Trim the colors slice to at most MaxCustomColors entries before calling the API","Merge duplicate or unused colors to reduce the count below the limit","If the palette came from a config/history file, remove excess entries from that file"],"exampleFix":"// before\nret, err := av.NormalizeAttributeViewCustomColors(colors, true)\n// after\nif len(colors) > av.MaxCustomColors {\n    colors = colors[:av.MaxCustomColors]\n}\nret, err := av.NormalizeAttributeViewCustomColors(colors, true)","handlingStrategy":"validation","validationCode":"if len(colors) > av.MaxCustomColors {\n    return fmt.Errorf(\"too many colors: %d > %d\", len(colors), av.MaxCustomColors)\n}","typeGuard":null,"tryCatchPattern":"if _, err := av.NormalizeAttributeViewCustomColors(colors, true); err != nil {\n    if strings.Contains(err.Error(), \"item limit\") { colors = colors[:av.MaxCustomColors] }\n}","preventionTips":["Check len(colors) against MaxCustomColors before appending","Merge duplicate colors instead of adding new entries","Never hand-edit palette files without counting entries"],"tags":["attribute-view","limit","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"}