{"record":{"id":"972b0c36664a4628","repo":"siyuan-note/siyuan","slug":"workspace-attribute-view-palette-update-must-not-b","errorCode":null,"errorMessage":"workspace attribute view palette update must not be null","messagePattern":"workspace attribute view palette update must not be null","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":180,"sourceCode":"\twaitForSyncingStorages()\n\tinlineStylesLock.Lock()\n\tdefer inlineStylesLock.Unlock()\n\n\tcurrent, err := loadInlineStyles()\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n\treturn setInlineStylesData(styles, current.AV)\n}\n\n// 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)","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L162-L198","documentation":"SetWorkspaceAVPalette updates the workspace attribute-view color palette under the inline-styles lock. It rejects a nil update argument with 'workspace attribute view palette update must not be null' before touching stored styles.","triggerScenarios":"Calling `SetWorkspaceAVPalette(nil)`, e.g. from an API handler whose request body failed to deserialize into a *WorkspaceAVPaletteUpdate and left the pointer nil.","commonSituations":"Frontend sends an empty/missing payload that the API layer maps to nil; a caller passes a pointer obtained from a failed decode.","solutions":["Check the update pointer for nil before calling and return a client-side validation error","In the API layer, reject requests with missing palette payload before invoking the kernel function","Ensure the frontend always sends colors/order fields when saving the palette"],"exampleFix":"// before\nret, changed, err := model.SetWorkspaceAVPalette(update)\n// after\nif update == nil {\n    return nil, errors.New(\"palette update payload is required\")\n}\nret, changed, err := model.SetWorkspaceAVPalette(update)","handlingStrategy":"type-guard","validationCode":"if update == nil {\n    return errors.New(\"palette update payload is required\")\n}","typeGuard":"func validPaletteUpdate(u *model.WorkspaceAVPaletteUpdate) bool {\n    return u != nil && u.Colors != nil && u.Order != nil\n}","tryCatchPattern":"ret, changed, err := model.SetWorkspaceAVPalette(update)\nif err != nil {\n    return nil, err\n}","preventionTips":["Deserialize request bodies with explicit empty-payload rejection","Always send colors and order when saving the palette","Unit-test the API handler with a nil payload"],"tags":["null-argument","attribute-view","api"],"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"}