siyuan-note/siyuan · error
duplicated attribute view custom color index
Error message
duplicated attribute view custom color index [%d]
What it means
NormalizeAttributeViewCustomColors requires each custom color to have a unique Index. In strict mode, encountering a second color with an already-seen index aborts with this error; in non-strict mode the duplicate is silently skipped. Indexes identify colors in the palette order, so duplicates are ambiguous.
Solutions
- Assign each color a unique Index within [CustomColorMinIndex, CustomColorMaxIndex] before saving
- Deduplicate entries by Index, keeping the newest one
- Renumber indexes sequentially after any merge or deletion
Example fix
// before
{"index":1,"light":{...}}, {"index":1,"light":{...}}
// after
{"index":1,"light":{...}}, {"index":2,"light":{...}} Defensive patterns
Strategy: validation
Validate before calling
seen := map[int]bool{}
for _, c := range colors {
if seen[c.Index] { return fmt.Errorf("duplicate index %d", c.Index) }
seen[c.Index] = true
} Try / catch
if _, err := av.NormalizeAttributeViewCustomColors(colors, true); err != nil {
if strings.Contains(err.Error(), "duplicated") { renumber(colors) }
} Prevention
- Generate indexes from a counter or list position, never from user input
- After merging palettes, renumber all indexes sequentially
- Deduplicate by Index before saving
When it happens
Trigger: Calling NormalizeAttributeViewCustomColors (strict=true) with a list where two AttributeViewCustomColor entries share the same Index, e.g. via setAttrViewCustomColors with hand-built colors or a decoded historical palette containing duplicated indexes.
Common situations: Merging palettes from two workspaces without reassigning indexes; programmatic generation of colors using a non-unique counter; manual JSON edits copying an entry but forgetting to bump its index.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- duplicate workspace attribute view builtin color update
- duplicated new item template id
- at least one visible view is required
- attribute view custom color index
- attribute view custom color must not be null
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/7b0fcf59e906bbea.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/av/color.go:110
// NormalizeAttributeViewCustomColors 校验并规范化数据库自定义颜色。
func NormalizeAttributeViewCustomColors(colors []*AttributeViewCustomColor, strict bool) (ret []*AttributeViewCustomColor, err error) {
if strict && MaxCustomColors < len(colors) {
return nil, fmt.Errorf("attribute view custom colors count exceeds the %d item limit", MaxCustomColors)
}
indexes := map[int]struct{}{}
for _, color := range colors {
normalized, normalizeErr := normalizeAttributeViewCustomColor(color)
if nil != normalizeErr {
if strict {
return nil, normalizeErr
}
continue
}
if _, ok := indexes[normalized.Index]; ok {
if strict {
return nil, fmt.Errorf("duplicated attribute view custom color index [%d]", normalized.Index)
}
continue
}
indexes[normalized.Index] = struct{}{}
ret = append(ret, normalized)
}
sort.Slice(ret, func(i, j int) bool {
return ret[i].Index < ret[j].Index
})
if nil == ret {
ret = []*AttributeViewCustomColor{}
}
return
}
func normalizeAttributeViewCustomColor(color *AttributeViewCustomColor) (ret *AttributeViewCustomColor, err error) {
if nil == color {View on GitHub (pinned to 9f775e8a12)