{"record":{"id":"9febd4410c3dfe67","repo":"siyuan-note/siyuan","slug":"invalid-new-item-template-target-type-s","errorCode":null,"errorMessage":"invalid new item template target type [%s]","messagePattern":"invalid new item template target type \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/new_item_template.go","lineNumber":74,"sourceCode":"\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)\n\t\t}\n\t\ttemplateIDs[itemTemplate.ID] = true\n\t\tif NewItemTargetDetached != itemTemplate.TargetType && NewItemTargetDocument != itemTemplate.TargetType {\n\t\t\treturn fmt.Errorf(\"invalid new item template target type [%s]\", itemTemplate.TargetType)\n\t\t}\n\t\tif NewItemTargetDocument != itemTemplate.TargetType {\n\t\t\titemTemplate.Icon = \"\"\n\t\t\titemTemplate.HideInFileTree = false\n\t\t}\n\t\titemTemplate.ContentTemplatePath = strings.TrimSpace(itemTemplate.ContentTemplatePath)\n\t\tif nil != itemTemplate.SaveLocation {\n\t\t\titemTemplate.SaveLocation.BoxID = strings.TrimSpace(itemTemplate.SaveLocation.BoxID)\n\t\t\titemTemplate.SaveLocation.PathTemplate = strings.TrimSpace(itemTemplate.SaveLocation.PathTemplate)\n\t\t}\n\t\tif err := av.normalizeNewItemTemplateFieldValues(itemTemplate); nil != err {\n\t\t\treturn err\n\t\t}\n\t\ttemplates = append(templates, itemTemplate)\n\t}\n\tif \"\" != defaultTemplateID && !templateIDs[defaultTemplateID] {\n\t\treturn fmt.Errorf(\"default new item template [%s] not found\", defaultTemplateID)\n\t}","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/new_item_template.go#L56-L92","documentation":"SetNewItemTemplates validates each new-item template's TargetType and rejects any value that is neither NewItemTargetDetached nor NewItemTargetDocument. The attribute view only supports creating detached rows or new documents from a template, so any other TargetType string is treated as an invalid configuration and the whole SetNewItemTemplates call fails without modifying the view.","triggerScenarios":"Calling AttributeView.SetNewItemTemplates with a config whose Templates[i].TargetType is an unknown/unrecognized value (anything other than the NewItemTargetDetached or NewItemTargetDocument constants, e.g. a typo'd or empty string from hand-built config or a plugin).","commonSituations":"Plugins or scripts constructing NewItemTemplatesConfig manually with a misspelled TargetType; older persisted configs written before the TargetType constants were stabilized; serialized JSON where the field was deserialized as an unexpected value.","solutions":["Set TargetType to the exported constant av.NewItemTargetDetached for detached-row templates","Set TargetType to av.NewItemTargetDocument for document-creating templates","Check the serialized config JSON for a typo or stale value in the target type field and correct it to one of the two supported constants"],"exampleFix":"// before\nitemTemplate.TargetType = \"document\"\n_ = av.SetNewItemTemplates(config)\n// after\nitemTemplate.TargetType = av.NewItemTargetDocument\nerr := av.SetNewItemTemplates(config)","handlingStrategy":"validation","validationCode":"if itemTemplate.TargetType != av.NewItemTargetDetached && itemTemplate.TargetType != av.NewItemTargetDocument {\n\treturn fmt.Errorf(\"unsupported target type %q\", itemTemplate.TargetType)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always assign TargetType from the exported av.NewItemTarget* constants, never string literals","Validate the whole NewItemTemplatesConfig before calling SetNewItemTemplates so one bad template does not abort the batch"],"tags":["attribute-view","validation","enum"],"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"}