siyuan-note/siyuan · error
duplicate inline style ID
Error message
duplicate inline style ID [%s]
What it means
Inline style IDs must be unique across the list; normalizeInlineStyles tracks every ID it has seen and rejects the save/load if a second style reuses one. Duplicate IDs would make it ambiguous which theme definition a styled span refers to, so the whole operation fails atomically.
Solutions
- Regenerate a unique ID (ast.NewNodeID()) for the duplicated style before saving
- Leave IDs empty and let generateIDs (setInlineStylesData path) mint unique ones
- Deduplicate the []*InlineStyle slice by ID in the caller before calling the API
- If loading fails, delete or re-ID one of the duplicate entries in the inline styles JSON
Example fix
// before
SetInlineStyles([]*InlineStyle{
{ID: "20240101120000-aaaa", Name: "A"},
{ID: "20240101120000-aaaa", Name: "B"}, // duplicate
})
// after
SetInlineStyles([]*InlineStyle{
{ID: "20240101120000-aaaa", Name: "A"},
{ID: ast.NewNodeID(), Name: "B"},
}) Defensive patterns
Strategy: validation
Validate before calling
func uniqueStyleIDs(styles []*InlineStyle) bool {
seen := map[string]struct{}{}
for _, s := range styles {
id := strings.TrimSpace(s.ID)
if _, dup := seen[id]; dup {
return false
}
seen[id] = struct{}{}
}
return true
} Try / catch
if _, _, err := model.SetInlineStyles(styles); err != nil {
if strings.HasPrefix(err.Error(), "duplicate inline style ID") {
styles = regenerateDuplicateIDs(styles) // then retry
}
return err
} Prevention
- Deduplicate by ID before saving
- When duplicating a style as a template, always regenerate its ID
- Mint IDs from a single source (ast.NewNodeID) to avoid collisions
When it happens
Trigger: Passing two *InlineStyle entries with the same ID to model.SetInlineStyles / model.SetInlineStylesData; a config file written by a buggy external tool or a failed merge containing two styles with one ID; copy-pasting a style entry in the JSON without changing its ID; concurrently saving two lists that both minted the same generated ID (unlikely but guarded).
Common situations: Duplicating a JSON style object to create a variant but forgetting to regenerate the ID; sync conflicts concatenating two versions of the styles array; scripts appending styles to the config without deduplication.
Related errors
- inline style must not be null
- inline style name exceeds the
- inline style name must not be empty
- invalid inline style ID
- invalid light theme of inline style
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/b16b6fc4fd022500.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/inline_style.go:667
for _, style := range styles {
if style == nil {
return nil, errors.New("inline style must not be null")
}
id := strings.TrimSpace(style.ID)
if id == "" && generateIDs {
for {
id = ast.NewNodeID()
if _, exists := ids[id]; !exists {
break
}
}
}
if !ast.IsNodeIDPattern(id) {
return nil, fmt.Errorf("invalid inline style ID [%s]", id)
}
if _, exists := ids[id]; exists {
return nil, fmt.Errorf("duplicate inline style ID [%s]", id)
}
ids[id] = struct{}{}
name := strings.TrimSpace(style.Name)
if name == "" {
return nil, errors.New("inline style name must not be empty")
}
if maxInlineStyleNameRunes < utf8.RuneCountInString(name) {
return nil, fmt.Errorf("inline style name exceeds the %d character limit", maxInlineStyleNameRunes)
}
if style.Light == nil || style.Dark == nil {
return nil, fmt.Errorf("inline style [%s] must define light and dark themes", id)
}
light, err := normalizeInlineStyleTheme(style.Light)
if err != nil {
return nil, fmt.Errorf("invalid light theme of inline style [%s]: %w", id, err)
}View on GitHub (pinned to 9f775e8a12)