{"record":{"id":"e0c4a0dfeb1a8f0f","repo":"siyuan-note/siyuan","slug":"clone-new-item-template-failed","errorCode":null,"errorMessage":"clone new item template failed","messagePattern":"clone new item template failed","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/new_item_template.go","lineNumber":52,"sourceCode":"\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 {\n\t\t\t// 非法图标值置空，防止存储可执行标记\n\t\t\t// https://github.com/siyuan-note/siyuan/security/advisories/GHSA-vx5w-qrvp-mmcq\n\t\t\titemTemplate.Icon = \"\"\n\t\t}\n\t\tif \"\" == itemTemplate.Name {\n\t\t\treturn errors.New(\"new item template name is empty\")\n\t\t}\n\t\tif !ast.IsNodeIDPattern(itemTemplate.ID) {\n\t\t\treturn fmt.Errorf(\"invalid new item template id [%s]\", itemTemplate.ID)\n\t\t}\n\t\tif templateIDs[itemTemplate.ID] {\n\t\t\treturn fmt.Errorf(\"duplicated new item template id [%s]\", itemTemplate.ID)","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/new_item_template.go#L34-L70","documentation":"During SetNewItemTemplates, each template is deep-copied via cloneNewItemTemplate so the view never aliases caller data. If cloning fails (cloneNewItemTemplate returns nil, e.g. nil or corrupt inner data), the whole operation aborts with this generic error.","triggerScenarios":"Supplying a *NewItemTemplate in config.Templates that cloneNewItemTemplate cannot clone — practically a template entry whose inner structures fail to copy or an entry that yields nil after cloning despite passing the nil check.","commonSituations":"Constructing templates programmatically with partially initialized fields; deserialized templates from JSON with missing embedded objects.","solutions":["Inspect each NewItemTemplate in the config and ensure all required inner fields (name, id, target fields) are populated.","Rebuild the config from a known-good serialization instead of reusing partially constructed objects.","Skip or normalize invalid entries before calling SetNewItemTemplates."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"for _, t := range cfg.Templates {\n\tif t == nil || t.ID == \"\" || t.Name == \"\" { /* drop or repair invalid entries */ }\n}","typeGuard":null,"tryCatchPattern":"if err := view.SetNewItemTemplates(cfg); err != nil && err.Error() == \"clone new item template failed\" {\n\t// rebuild cfg from a known-good source and retry once\n}","preventionTips":["Build templates from fully initialized structs only","Round-trip templates through JSON marshal/unmarshal to normalize before saving","Drop nil or half-populated entries before validation"],"tags":["attribute-view","clone","go"],"backgroundTag":"invalid-argument-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"}