{"record":{"id":"4bf0fe879a938782","repo":"siyuan-note/siyuan","slug":"duplicate-workspace-attribute-view-builtin-color-u","errorCode":null,"errorMessage":"duplicate workspace attribute view builtin color update [%d]","messagePattern":"duplicate workspace attribute view builtin color update \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":198,"sourceCode":"\t\treturn nil, false, errors.New(\"workspace attribute view palette update must not be null\")\n\t}\n\tcurrent, err := loadInlineStyles()\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n\tcurrentAV := current.AV\n\tcurrent.AV = &InlineStyleAV{Colors: update.Colors, Order: update.Order}\n\tupdatedIndexes := map[int]struct{}{}\n\tfor _, patch := range update.BuiltinColors {\n\t\tif patch == nil {\n\t\t\treturn nil, false, errors.New(\"workspace attribute view builtin color update must not be null\")\n\t\t}\n\t\tif patch.Index < minBuiltinColorIndex || neutralAVColorIndex < patch.Index {\n\t\t\treturn nil, false, fmt.Errorf(\"builtin color index [%d] must be between %d and %d\", patch.Index,\n\t\t\t\tminBuiltinColorIndex, neutralAVColorIndex)\n\t\t}\n\t\tif _, duplicated := updatedIndexes[patch.Index]; duplicated {\n\t\t\treturn nil, false, fmt.Errorf(\"duplicate workspace attribute view builtin color update [%d]\", patch.Index)\n\t\t}\n\t\tupdatedIndexes[patch.Index] = struct{}{}\n\t\tfiltered := current.Builtin.Colors[:0]\n\t\tfor _, color := range current.Builtin.Colors {\n\t\t\tif color.Index != patch.Index {\n\t\t\t\tfiltered = append(filtered, color)\n\t\t\t}\n\t\t}\n\t\tcurrent.Builtin.Colors = filtered\n\t\tif patch.Customized {\n\t\t\tcurrent.Builtin.Colors = append(current.Builtin.Colors, &InlineStyleBuiltinColor{\n\t\t\t\tIndex: patch.Index,\n\t\t\t\tLight: patch.Light,\n\t\t\t\tDark:  patch.Dark,\n\t\t\t})\n\t\t}\n\t\tfilteredHidden := current.Builtin.Hidden.AV[:0]\n\t\tfor _, index := range current.Builtin.Hidden.AV {","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L180-L216","documentation":"Each builtin color slot may be patched at most once per SetWorkspaceAVPalette call. A repeated index (tracked in updatedIndexes) fails with 'duplicate workspace attribute view builtin color update [%d]', preventing ambiguous conflicting writes to the same slot.","triggerScenarios":"Calling `SetWorkspaceAVPalette` where two or more elements of update.BuiltinColors share the same Index, detected via the updatedIndexes map.","commonSituations":"Frontend accumulates patches across UI events without deduplicating; merging palette changes from multiple sources produces repeated indexes.","solutions":["Deduplicate update.BuiltinColors by Index (keep the last patch) before calling","Rebuild the patch list from final desired state rather than appending incremental edits","At the API boundary, reject or merge duplicate-index payloads"],"exampleFix":"// before\nret, _, err := model.SetWorkspaceAVPalette(&model.WorkspaceAVPaletteUpdate{BuiltinColors: patches})\n// after\nlatest := map[int]*model.WorkspaceAVBuiltinColorUpdate{}\nfor _, p := range patches {\n    latest[p.Index] = p\n}\nunique := make([]*model.WorkspaceAVBuiltinColorUpdate, 0, len(latest))\nfor _, p := range latest {\n    unique = append(unique, p)\n}\nret, _, err := model.SetWorkspaceAVPalette(&model.WorkspaceAVPaletteUpdate{BuiltinColors: unique})","handlingStrategy":"validation","validationCode":"seen := map[int]bool{}\nfor _, p := range patches {\n    if seen[p.Index] {\n        return fmt.Errorf(\"duplicate builtin color index %d\", p.Index)\n    }\n    seen[p.Index] = true\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Deduplicate patches by index before sending","Build patches from final state, not incremental UI events","Test palette-save flows that fire multiple change events"],"tags":["duplicate","attribute-view","validation"],"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"}