{"record":{"id":"258982342a32c48c","repo":"siyuan-note/siyuan","slug":"new-item-templates-config-is-nil","errorCode":null,"errorMessage":"new item templates config is nil","messagePattern":"new item templates config is nil","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/new_item_template.go","lineNumber":40,"sourceCode":"\t\"sort\"\n\t\"strings\"\n\n\t\"github.com/88250/lute/ast\"\n\n\t\"github.com/siyuan-note/siyuan/kernel/util\"\n)\n\n// PrunedNewItemTemplateOption 描述创建条目前从模板字段值中移除的无效选项。\ntype PrunedNewItemTemplateOption struct {\n\tTemplateID string\n\tKeyID      string\n\tValues     []string\n}\n\n// SetNewItemTemplates 校验并替换数据库的新增条目模板配置。\nfunc (av *AttributeView) SetNewItemTemplates(config *NewItemTemplatesConfig) error {\n\tif nil == config {\n\t\treturn errors.New(\"new item templates config is nil\")\n\t}\n\n\ttemplates := make([]*NewItemTemplate, 0, len(config.Templates))\n\ttemplateIDs := map[string]bool{}\n\tdefaultTemplateID := config.DefaultTemplateID\n\tfor _, itemTemplate := range config.Templates {\n\t\tif nil == itemTemplate {\n\t\t\tcontinue\n\t\t}\n\t\titemTemplate = cloneNewItemTemplate(itemTemplate)\n\t\tif nil == itemTemplate {\n\t\t\treturn errors.New(\"clone new item template failed\")\n\t\t}\n\t\titemTemplate.Name = strings.TrimSpace(itemTemplate.Name)\n\t\titemTemplate.Icon = strings.TrimSpace(itemTemplate.Icon)\n\t\tif filteredIcon, valid := util.FilterIconValue(itemTemplate.Icon); valid {\n\t\t\titemTemplate.Icon = filteredIcon\n\t\t} else {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/new_item_template.go#L22-L58","documentation":"SetNewItemTemplates validates and replaces the database's new-item template configuration. A nil config argument is rejected outright because there is nothing valid to install — clearing templates must use an explicit empty config instead.","triggerScenarios":"Calling av.AttributeView.SetNewItemTemplates(nil), typically when the caller builds the config from optional JSON fields that were all absent.","commonSituations":"API/plugin payload missing the templates object; deserializing an empty JSON body into a typed pointer yielding nil; refactored code passing a possibly-nil pointer without a check.","solutions":["Pass a non-nil &NewItemTemplatesConfig{}, e.g. with Templates: []*NewItemTemplate{} to clear all templates.","Check the pointer for nil at the call site and convert it to an empty config.","When reading config from a request, default an absent object to an empty struct before calling."],"exampleFix":"// before\nav.SetNewItemTemplates(nil)\n// after\nav.SetNewItemTemplates(&av.NewItemTemplatesConfig{Templates: []*av.NewItemTemplate{}})","handlingStrategy":"validation","validationCode":"if cfg == nil {\n\tcfg = &av.NewItemTemplatesConfig{}\n}","typeGuard":"func validTemplatesConfig(c *av.NewItemTemplatesConfig) bool { return c != nil }","tryCatchPattern":null,"preventionTips":["Never pass nil to SetNewItemTemplates; use an empty struct to clear templates","Default missing JSON payloads to an empty config struct at deserialization","Add a nil-check helper around all config-mutating AV APIs"],"tags":["attribute-view","null-argument","go"],"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"}