{"record":{"id":"9f69067f42ac7d8f","repo":"siyuan-note/siyuan","slug":"attribute-view-item-markdown-is-nil","errorCode":null,"errorMessage":"attribute view item markdown is nil","messagePattern":"attribute view item markdown is nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_new_item.go","lineNumber":89,"sourceCode":"// CreateAttributeViewItemDocsResult 描述将游离条目批量转换为文档后的结果。\ntype CreateAttributeViewItemDocsResult struct {\n\tItemIDs        []string     `json:\"itemIDs\"`\n\tBlockIDs       []string     `json:\"blockIDs\"`\n\tSkippedItemIDs []string     `json:\"skippedItemIDs,omitempty\"`\n\tWarnings       []string     `json:\"warnings,omitempty\"`\n\tTransaction    *Transaction `json:\"-\"`\n}\n\n// CreateAttributeViewItem 按指定模板创建一个数据库条目。templateID 为空时创建空白游离条目。\nfunc CreateAttributeViewItem(avID, blockID, viewID, templateID, previousID, groupID string) (*CreateAttributeViewItemResult, error) {\n\treturn createAttributeViewItem(avID, blockID, viewID, templateID, previousID, groupID, nil)\n}\n\n// CreateAttributeViewItemWithMarkdown 按指定的文档类型模板创建数据库条目，并使用传入的 Markdown 创建绑定文档。\nfunc CreateAttributeViewItemWithMarkdown(avID, blockID, viewID, templateID, previousID, groupID string,\n\tdocument *CreateAttributeViewItemMarkdown) (*CreateAttributeViewItemResult, error) {\n\tif nil == document {\n\t\treturn nil, errors.New(\"attribute view item markdown is nil\")\n\t}\n\treturn createAttributeViewItem(avID, blockID, viewID, templateID, previousID, groupID, document)\n}\n\nfunc createAttributeViewItem(avID, blockID, viewID, templateID, previousID, groupID string,\n\tdocument *CreateAttributeViewItemMarkdown) (*CreateAttributeViewItemResult, error) {\n\tattrView, err := avParseView(avID, blockID)\n\tif nil != err {\n\t\treturn nil, err\n\t}\n\tcreatedAt := time.Now()\n\titemTemplate := attrView.GetNewItemTemplate(templateID)\n\tvar prunedOptions []*av.PrunedNewItemTemplateOption\n\tif \"\" != templateID && nil == itemTemplate {\n\t\treturn nil, fmt.Errorf(\"new item template [%s] not found\", templateID)\n\t}\n\tif nil == itemTemplate {\n\t\titemTemplate = &av.NewItemTemplate{TargetType: av.NewItemTargetDetached}","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_new_item.go#L71-L107","documentation":"CreateAttributeViewItemWithMarkdown creates a database item bound to a new document generated from the given Markdown. The document parameter is a pointer, and the function rejects a nil pointer outright because there is no Markdown content to create the bound document from.","triggerScenarios":"Calling CreateAttributeViewItemWithMarkdown with the document argument explicitly nil (or a nil *CreateAttributeViewItemMarkdown variable passed through).","commonSituations":"Callers that only need a detached item mistakenly using the WithMarkdown variant; a markdown value built conditionally that ended up nil; wrappers that forward nil when no template content was loaded.","solutions":["Pass a non-nil *CreateAttributeViewItemMarkdown with valid Markdown content","If no bound document is needed, call CreateAttributeViewItem instead","Guard the call site: construct the document struct before invoking, and fall back to CreateAttributeViewItem when no content is available"],"exampleFix":"// before\nres, err := CreateAttributeViewItemWithMarkdown(avID, blockID, viewID, tplID, prevID, groupID, nil)\n// after\nvar doc *CreateAttributeViewItemMarkdown\nif md != \"\" {\n    doc = &CreateAttributeViewItemMarkdown{Markdown: md}\n}\nres, err := CreateAttributeViewItemWithMarkdown(avID, blockID, viewID, tplID, prevID, groupID, doc)","handlingStrategy":"type-guard","validationCode":"if (!document || typeof document.markdown !== 'string') {\n  return CreateAttributeViewItem(avID, blockID, viewID, templateID, previousID, groupID);\n}","typeGuard":"function hasMarkdownDocument(doc) {\n  return doc !== null && doc !== undefined && typeof doc === 'object';\n}","tryCatchPattern":"try {\n  return await api.createAttributeViewItemWithMarkdown({avID, blockID, document});\n} catch (e) {\n  if (e.message.includes('item markdown is nil')) {\n    return await api.createAttributeViewItem({avID, blockID}); // detached item\n  }\n}","preventionTips":["Construct the markdown document before calling the WithMarkdown variant","Use the plain CreateAttributeViewItem when no document is needed","Avoid forwarding nullable document parameters from wrappers"],"tags":["attribute-view","null-argument","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"}