{"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":"validation","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/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L702-L738","documentation":"Builtin color indexes must be unique so each palette slot maps to exactly one color definition. When two builtin.colors entries share the same index, normalization fails fast with this error instead of silently letting the later entry overwrite the earlier one.","triggerScenarios":"setInlineStylesData or loadInlineStyles encounters two entries in builtin.colors with identical index values in inline-styles.json.","commonSituations":"Copy-pasting an existing color entry to add a new one and forgetting to bump the index; a merge conflict resolution in inline-styles.json that kept both sides' entries; a script that re-inserts entries without deduplication.","solutions":["Find the duplicated index in builtin.colors and renumber one of the conflicting entries to a free value in 1..14","Deduplicate the array if one entry is stale or identical","Run a quick pre-check (e.g. jq or a script counting index occurrences) before saving","Resync/verify the workspace after fixing so all clients load the corrected file"],"exampleFix":"// before\n\"colors\": [ {\"index\": 3, ...}, {\"index\": 3, ...} ]\n// after\n\"colors\": [ {\"index\": 3, ...}, {\"index\": 4, ...} ]","handlingStrategy":"validation","validationCode":"const seen = new Set();\nfor (const [i, c] of (cfg.builtin?.colors ?? []).entries()) {\n  if (seen.has(c.index)) throw new Error(`duplicate builtin color index ${c.index} at entry ${i}`);\n  seen.add(c.index);\n}","typeGuard":"function indexesUnique(colors) { return new Set(colors.map(c => c?.index)).size === colors.length; }","tryCatchPattern":"if err := replaceWorkspaceAVPalette(colors, order); err != nil {\n    if strings.Contains(err.Error(), \"duplicate builtin color index\") { /* dedupe by index before retry */ }\n    return err\n}","preventionTips":["Copy-paste entries? Always change the index immediately after pasting","Resolve merge conflicts in inline-styles.json by deduplicating, not by keeping both sides","Run a jq/script check for duplicate indexes as a pre-save lint","Keep palette edits within one client to avoid sync merge duplication"],"tags":["config","validation","duplicate-key","inline-styles"],"backgroundTag":"conflicting-config-options","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"}