{"record":{"id":"4ab319fc39db3d30","repo":"siyuan-note/siyuan","slug":"duplicate-builtin-color-index-d","errorCode":null,"errorMessage":"duplicate builtin color index [%d]","messagePattern":"duplicate builtin color index \\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":720,"sourceCode":"}\n\nfunc normalizeInlineStyleBuiltin(builtin *InlineStyleBuiltin) (ret *InlineStyleBuiltin, err error) {\n\tret = newEmptyInlineStyleBuiltin()\n\tif builtin == nil {\n\t\treturn ret, nil\n\t}\n\n\tcolorIndexes := make(map[int]struct{}, len(builtin.Colors))\n\tfor _, color := range builtin.Colors {\n\t\tif color == nil {\n\t\t\treturn nil, errors.New(\"builtin color must not be null\")\n\t\t}\n\t\tif color.Index < minBuiltinColorIndex || neutralAVColorIndex < color.Index {\n\t\t\treturn nil, fmt.Errorf(\"builtin color index [%d] must be between %d and %d\", color.Index,\n\t\t\t\tminBuiltinColorIndex, neutralAVColorIndex)\n\t\t}\n\t\tif _, exists := colorIndexes[color.Index]; exists {\n\t\t\treturn nil, fmt.Errorf(\"duplicate builtin color index [%d]\", color.Index)\n\t\t}\n\t\tcolorIndexes[color.Index] = struct{}{}\n\n\t\tlight, dark, err := normalizeInlineStyleThemePair(color.Light, color.Dark, fmt.Sprintf(\"builtin color [%d]\", color.Index))\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tret.Colors = append(ret.Colors, &InlineStyleBuiltinColor{Index: color.Index, Light: light, Dark: dark})\n\t}\n\tsort.Slice(ret.Colors, func(i, j int) bool {\n\t\treturn ret.Colors[i].Index < ret.Colors[j].Index\n\t})\n\n\tstyleIDs := make(map[string]struct{}, len(builtin.Styles))\n\tfor _, style := range builtin.Styles {\n\t\tif style == nil {\n\t\t\treturn nil, errors.New(\"builtin style must not be null\")\n\t\t}","sourceCodeStart":702,"sourceCodeEnd":738,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/inline_style.go#L702-L738","documentation":"Two builtin color entries declare the same `index`. Builtin color indexes are unique identifiers for the 14 palette slots, so normalizeInlineStyleBuiltin rejects duplicates to keep palette order, hiding configuration (builtin.Hidden.Color/AV), and AV color rendering unambiguous.","triggerScenarios":"setInlineStylesData or loadInlineStyles with builtin.colors containing two entries with the same index value, e.g. two entries both with `\"index\": 5`.","commonSituations":"Copy-pasting a color entry and forgetting to change its index; merging configuration files from two workspaces; a script cloning the last array element to add a new color.","solutions":["Find the duplicated index in builtin.colors of inline-styles.json and renumber one entry to an unused index between 1 and 14.","If both entries are unintended duplicates of the same palette slot, delete the redundant entry.","Validate the array programmatically (collect indexes into a set) before saving the config or sending it via setInlineStylesData."],"exampleFix":"// before\n[{\"index\": 3, ...}, {\"index\": 3, ...}]\n// after\n[{\"index\": 3, ...}, {\"index\": 4, ...}]","handlingStrategy":"validation","validationCode":"const seen = new Set();\nfor (const c of config.builtin.colors) {\n  if (seen.has(c.index)) throw new Error(`duplicate builtin color index ${c.index}`);\n  seen.add(c.index);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When cloning a color entry to create a new one, always update its index first.","Run the duplicate-index set check as part of any script that merges or generates inline style configs."],"tags":["go","configuration","inline-styles","duplicate-key"],"backgroundTag":"invalid-config-value","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}