{"record":{"id":"2eb2d63a7f7815b4","repo":"siyuan-note/siyuan","slug":"attribute-view-custom-color-d-is-still-in-use","errorCode":null,"errorMessage":"attribute view custom color [%d] is still in use","messagePattern":"attribute view custom color \\[(.+?)\\] is still in use","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view.go","lineNumber":8925,"sourceCode":"\tif nil == order {\n\t\torder = oldOrder\n\t}\n\n\tretainedIndexes := map[int]struct{}{}\n\tfor _, color := range colors {\n\t\tretainedIndexes[color.Index] = struct{}{}\n\t}\n\tusedIndexes := map[int]struct{}{}\n\tfor _, index := range attrView.UsedCustomColorIndexes() {\n\t\tusedIndexes[index] = struct{}{}\n\t}\n\tfor _, oldColor := range oldColors {\n\t\tif nil == oldColor {\n\t\t\tcontinue\n\t\t}\n\t\tif _, retained := retainedIndexes[oldColor.Index]; !retained {\n\t\t\tif _, used := usedIndexes[oldColor.Index]; used {\n\t\t\t\treturn fmt.Errorf(\"attribute view custom color [%d] is still in use\", oldColor.Index)\n\t\t\t}\n\t\t}\n\t}\n\n\tif err = replaceWorkspaceAVPalette(colors, order); nil != err {\n\t\treturn\n\t}\n\tReloadAttrView(attrView.ID)\n\tfor _, relatedAvID := range av.GetSrcAvIDs(attrView.ID) {\n\t\tif relatedAvID != attrView.ID {\n\t\t\tReloadAttrView(relatedAvID)\n\t\t}\n\t}\n\treturn\n}\n\nfunc (tx *Transaction) doRemoveAttrViewColOption(operation *Operation) (ret *TxErr) {\n\terr := tx.mutateAttributeViewOption(operation, true)","sourceCodeStart":8907,"sourceCodeEnd":8943,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view.go#L8907-L8943","documentation":"When replacing the workspace attribute-view color palette, a custom color that some views still reference cannot be removed. The kernel computes which old color indexes are still used by views; if a color slated for removal (not retained) is still in use, the whole palette replacement is rejected, reporting the offending color index.","triggerScenarios":"Calling the replace/set custom colors API with a new palette that drops a color index currently referenced by attribute view cells (usedIndexes contains an index absent from retainedIndexes).","commonSituations":"Plugin rewriting the palette without first remapping views that use existing colors; user deleting a color while views still point at it; bulk palette import that doesn't carry over in-use colors.","solutions":["Retain (keep) every color index that is currently in use, or first remap those views to other colors, then replace the palette","Enumerate views' color usage before building the new palette and include all used indexes","Return/report the offending index from the error message and fix it in the payload","Retry the palette change after the dependent views are updated"],"exampleFix":"// before\nconst newColors = palette.filter(c => userRemoved(c)); // may drop colors still in use\n// after\nconst used = collectUsedColorIndexes(attrViews);\nconst newColors = palette.filter(c => userRemoved(c) || used.has(c.index)); // retain in-use colors","handlingStrategy":"validation","validationCode":"const used = collectUsedColorIndexes(attrViews); // indexes referenced by any view\nconst removed = oldColors.filter(c => !newPaletteRetains(c.index));\nconst stillUsed = removed.filter(c => used.has(c.index));\nif (stillUsed.length) throw new Error(`colors still in use: ${stillUsed.map(c => c.index).join(\",\")}`);","typeGuard":null,"tryCatchPattern":"try { await replacePalette(newColors, order); } catch (e) { const m = String(e).match(/custom color \\[(\\d+)\\] is still in use/); if (m) { remapOrRetain(parseInt(m[1])); retry(); } else { throw e; } }","preventionTips":["Scan all views for color usage before shrinking a palette","Remap views off a color before removing it","Only delete palette entries that have zero references"],"tags":["attribute-view","palette","conflict"],"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"}