siyuan-note/siyuan · error
duplicate builtin color index
Error message
duplicate builtin color index [%d]
What it means
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.
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
Example fix
// before
"colors": [ {"index": 3, ...}, {"index": 3, ...} ]
// after
"colors": [ {"index": 3, ...}, {"index": 4, ...} ] Defensive patterns
Strategy: validation
Validate before calling
const seen = new Set();
for (const [i, c] of (cfg.builtin?.colors ?? []).entries()) {
if (seen.has(c.index)) throw new Error(`duplicate builtin color index ${c.index} at entry ${i}`);
seen.add(c.index);
} Type guard
function indexesUnique(colors) { return new Set(colors.map(c => c?.index)).size === colors.length; } Try / catch
if err := replaceWorkspaceAVPalette(colors, order); err != nil {
if strings.Contains(err.Error(), "duplicate builtin color index") { /* dedupe by index before retry */ }
return err
} Prevention
- 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
When it happens
Trigger: setInlineStylesData or loadInlineStyles encounters two entries in builtin.colors with identical index values in inline-styles.json.
Common situations: 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.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- duplicate builtin style ID
- builtin color must not be null
- builtin style must not be null
- invalid builtin style ID
- must define color or backgroundColor
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/4ab319fc39db3d30.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/inline_style.go:720
}
func normalizeInlineStyleBuiltin(builtin *InlineStyleBuiltin) (ret *InlineStyleBuiltin, err error) {
ret = newEmptyInlineStyleBuiltin()
if builtin == nil {
return ret, nil
}
colorIndexes := make(map[int]struct{}, len(builtin.Colors))
for _, color := range builtin.Colors {
if color == nil {
return nil, errors.New("builtin color must not be null")
}
if color.Index < minBuiltinColorIndex || neutralAVColorIndex < color.Index {
return nil, fmt.Errorf("builtin color index [%d] must be between %d and %d", color.Index,
minBuiltinColorIndex, neutralAVColorIndex)
}
if _, exists := colorIndexes[color.Index]; exists {
return nil, fmt.Errorf("duplicate builtin color index [%d]", color.Index)
}
colorIndexes[color.Index] = struct{}{}
light, dark, err := normalizeInlineStyleThemePair(color.Light, color.Dark, fmt.Sprintf("builtin color [%d]", color.Index))
if err != nil {
return nil, err
}
ret.Colors = append(ret.Colors, &InlineStyleBuiltinColor{Index: color.Index, Light: light, Dark: dark})
}
sort.Slice(ret.Colors, func(i, j int) bool {
return ret.Colors[i].Index < ret.Colors[j].Index
})
styleIDs := make(map[string]struct{}, len(builtin.Styles))
for _, style := range builtin.Styles {
if style == nil {
return nil, errors.New("builtin style must not be null")
}View on GitHub (pinned to 9f775e8a12)