{"record":{"id":"3ca0917a2d06edc0","repo":"siyuan-note/siyuan","slug":"invalid-create-attribute-view-item-documents-save","errorCode":null,"errorMessage":"invalid create attribute view item documents save mode [%s]","messagePattern":"invalid create attribute view item documents save mode \\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_new_item.go","lineNumber":368,"sourceCode":"\tlock.Lock()\n\treturn lock.Unlock\n}\n\nfunc attributeViewItemDocumentTemplate(attrView *av.AttributeView, saveMode string) (*av.NewItemTemplate, error) {\n\tswitch saveMode {\n\tcase CreateAttributeViewItemDocsSaveModeSubDoc:\n\t\treturn &av.NewItemTemplate{\n\t\t\tTargetType:   av.NewItemTargetDocument,\n\t\t\tSaveLocation: &av.NewItemSaveLocation{},\n\t\t}, nil\n\tcase CreateAttributeViewItemDocsSaveModeTemplate:\n\t\titemTemplate := attrView.GetNewItemTemplate(attrView.DefaultTemplateID)\n\t\tif nil != itemTemplate && av.NewItemTargetDocument == itemTemplate.TargetType {\n\t\t\treturn itemTemplate, nil\n\t\t}\n\t\treturn &av.NewItemTemplate{TargetType: av.NewItemTargetDocument}, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"invalid create attribute view item documents save mode [%s]\", saveMode)\n\t}\n}\n\nfunc resolveAttributeViewNewItemTemplate(blockID string, itemTemplate *av.NewItemTemplate, createdAt time.Time) (*NewItemTemplatePreview, error) {\n\treturn resolveAttributeViewNewItemTemplateWithFallback(blockID, itemTemplate, createdAt, \"\")\n}\n\nfunc resolveAttributeViewNewItemTemplateWithFallback(blockID string, itemTemplate *av.NewItemTemplate, createdAt time.Time,\n\tprimaryFallback string) (*NewItemTemplatePreview, error) {\n\tboxID := \"\"\n\tif blockTree := treenode.GetBlockTree(blockID); blockTree != nil {\n\t\tboxID = blockTree.BoxID\n\t} else {\n\t\tfor _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {\n\t\t\tif blockTree := treenode.GetBlockTreeInBox(blockID, encBoxID); blockTree != nil {\n\t\t\t\tboxID = encBoxID\n\t\t\t\tbreak\n\t\t\t}","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_new_item.go#L350-L386","documentation":"attributeViewItemDocumentTemplate only accepts two save modes for CreateAttributeViewItemDocs: \"subDoc\" (CreateAttributeViewItemDocsSaveModeSubDoc) and \"template\" (CreateAttributeViewItemDocsSaveModeTemplate). Any other saveMode string hits the default branch and returns this error. It is a strict enum validation on the API parameter.","triggerScenarios":"Calling CreateAttributeViewItemDocs (API /api/attr/createAttributeViewItemDocs) with saveMode set to \"\", \"doc\", \"SubDoc\", or any value other than exactly \"subDoc\" or \"template\".","commonSituations":"Client code hard-coding a mode string instead of the exported constants; casing mistakes; older clients sending a mode name that was renamed when the feature was introduced.","solutions":["Pass exactly \"subDoc\" or \"template\" (prefer the exported constants model.CreateAttributeViewItemDocsSaveModeSubDoc / CreateAttributeViewItemDocsSaveModeTemplate)","Check the client payload/casing; the comparison is case-sensitive","If a default is desired, choose \"template\" explicitly, which falls back to the database's default document template"],"exampleFix":"// before\nres, err := model.CreateAttributeViewItemDocs(avID, blockID, \"document\", itemIDs)\n// after\nres, err := model.CreateAttributeViewItemDocs(avID, blockID, model.CreateAttributeViewItemDocsSaveModeSubDoc, itemIDs)","handlingStrategy":"validation","validationCode":"const validModes = map[string]bool{\"subDoc\": true, \"template\": true}\nif !validModes[saveMode] { return fmt.Errorf(\"unsupported saveMode %q\", saveMode) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass the exported constants CreateAttributeViewItemDocsSaveModeSubDoc / CreateAttributeViewItemDocsSaveModeTemplate","Never hard-code mode strings in client code","Remember the comparison is exact and case-sensitive"],"tags":["attribute-view","invalid-enum","go-kernel"],"backgroundTag":"invalid-enum-value","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"}