{"record":{"id":"b16b6fc4fd022500","repo":"siyuan-note/siyuan","slug":"duplicate-inline-style-id-s","errorCode":null,"errorMessage":"duplicate inline style ID [%s]","messagePattern":"duplicate inline style ID \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":667,"sourceCode":"\tfor _, style := range styles {\n\t\tif style == nil {\n\t\t\treturn nil, errors.New(\"inline style must not be null\")\n\t\t}\n\n\t\tid := strings.TrimSpace(style.ID)\n\t\tif id == \"\" && generateIDs {\n\t\t\tfor {\n\t\t\t\tid = ast.NewNodeID()\n\t\t\t\tif _, exists := ids[id]; !exists {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif !ast.IsNodeIDPattern(id) {\n\t\t\treturn nil, fmt.Errorf(\"invalid inline style ID [%s]\", id)\n\t\t}\n\t\tif _, exists := ids[id]; exists {\n\t\t\treturn nil, fmt.Errorf(\"duplicate inline style ID [%s]\", id)\n\t\t}\n\t\tids[id] = struct{}{}\n\n\t\tname := strings.TrimSpace(style.Name)\n\t\tif name == \"\" {\n\t\t\treturn nil, errors.New(\"inline style name must not be empty\")\n\t\t}\n\t\tif maxInlineStyleNameRunes < utf8.RuneCountInString(name) {\n\t\t\treturn nil, fmt.Errorf(\"inline style name exceeds the %d character limit\", maxInlineStyleNameRunes)\n\t\t}\n\t\tif style.Light == nil || style.Dark == nil {\n\t\t\treturn nil, fmt.Errorf(\"inline style [%s] must define light and dark themes\", id)\n\t\t}\n\n\t\tlight, err := normalizeInlineStyleTheme(style.Light)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid light theme of inline style [%s]: %w\", id, err)\n\t\t}","sourceCodeStart":649,"sourceCodeEnd":685,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L649-L685","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nSetInlineStyles([]*InlineStyle{\n  {ID: \"20240101120000-aaaa\", Name: \"A\"},\n  {ID: \"20240101120000-aaaa\", Name: \"B\"}, // duplicate\n})\n// after\nSetInlineStyles([]*InlineStyle{\n  {ID: \"20240101120000-aaaa\", Name: \"A\"},\n  {ID: ast.NewNodeID(),          Name: \"B\"},\n})","handlingStrategy":"validation","validationCode":"func uniqueStyleIDs(styles []*InlineStyle) bool {\n\tseen := map[string]struct{}{}\n\tfor _, s := range styles {\n\t\tid := strings.TrimSpace(s.ID)\n\t\tif _, dup := seen[id]; dup {\n\t\t\treturn false\n\t\t}\n\t\tseen[id] = struct{}{}\n\t}\n\treturn true\n}","typeGuard":null,"tryCatchPattern":"if _, _, err := model.SetInlineStyles(styles); err != nil {\n\tif strings.HasPrefix(err.Error(), \"duplicate inline style ID\") {\n\t\tstyles = regenerateDuplicateIDs(styles) // then retry\n\t}\n\treturn err\n}","preventionTips":["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"],"tags":["go","validation","uniqueness","inline-styles"],"backgroundTag":"duplicate-identifier","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"}