{"record":{"id":"d72d7524f052554d","repo":"siyuan-note/siyuan","slug":"workspace-attribute-view-builtin-color-update-must","errorCode":null,"errorMessage":"workspace attribute view builtin color update must not be null","messagePattern":"workspace attribute view builtin color update must not be null","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":191,"sourceCode":"// SetWorkspaceAVPalette 只更新数据库颜色配置，保留其他窗口可能同时修改的行级样式设置。\nfunc SetWorkspaceAVPalette(update *WorkspaceAVPaletteUpdate) (ret *InlineStyles, changed bool, err error) {\n\twaitForSyncingStorages()\n\tinlineStylesLock.Lock()\n\tdefer inlineStylesLock.Unlock()\n\n\tif update == nil {\n\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{","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L173-L209","documentation":"Within SetWorkspaceAVPalette, each entry of update.BuiltinColors must be a non-nil patch struct. A nil element triggers 'workspace attribute view builtin color update must not be null', aborting the whole palette update before any change is persisted.","triggerScenarios":"Calling `SetWorkspaceAVPalette` with `update.BuiltinColors` containing a nil *WorkspaceAVBuiltinColorUpdate element, e.g. a JSON array with a null item.","commonSituations":"Frontend constructs the patches array programmatically and appends a nil entry; JSON payload like \"builtinColors\":[null].","solutions":["Filter out nil elements from update.BuiltinColors before calling","Validate the request payload (no null array items) at the API boundary","Fix the frontend code that builds the builtin color patches array"],"exampleFix":"// before\npatches := collectBuiltinColorPatches()\nret, _, err := model.SetWorkspaceAVPalette(&model.WorkspaceAVPaletteUpdate{BuiltinColors: patches})\n// after\npatches := collectBuiltinColorPatches()\npatches = slices.DeleteFunc(patches, func(p *model.WorkspaceAVBuiltinColorUpdate) bool { return p == nil })\nret, _, err := model.SetWorkspaceAVPalette(&model.WorkspaceAVPaletteUpdate{BuiltinColors: patches})","handlingStrategy":"validation","validationCode":"for i, p := range update.BuiltinColors {\n    if p == nil {\n        return fmt.Errorf(\"builtinColors[%d] must not be null\", i)\n    }\n}","typeGuard":null,"tryCatchPattern":"if _, _, err := model.SetWorkspaceAVPalette(update); err != nil {\n    return apiError(err)\n}","preventionTips":["Validate JSON arrays for null items at the API boundary","Filter nil patches before building WorkspaceAVPaletteUpdate","Add a frontend test for the patches array construction"],"tags":["null-argument","attribute-view","validation"],"backgroundTag":"null-argument","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"}