{"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/251596fc0de2f9528c00c224252fd073a99973f4/kernel/av/new_item_template.go#L56-L92","documentation":"TargetType must be exactly NewItemTargetDetached or NewItemTargetDocument — the two valid creation targets for a new AV row (a detached block vs. a full document). Any other value, including the empty string, is rejected before the icon/hide-in-tree normalization that depends on the target.","triggerScenarios":"Frontend sends a stale or misspelled target constant; a future client introduces a new target type the running kernel does not recognize yet; manual API call with an arbitrary string.","commonSituations":"Version skew between frontend and kernel; typo in mode string; import authored against a newer schema.","solutions":["Send one of the two canonical constants defined in the av package.","If a newer target type is required, upgrade the kernel to a version that supports it.","Validate TargetType against the whitelist on the client before submission."],"exampleFix":"// before\n&av.NewItemTemplate{TargetType: \"doc\"}\n// after\n&av.NewItemTemplate{TargetType: av.NewItemTargetDocument}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isValidTargetType(t string) bool {\n    return t == av.NewItemTargetDetached || t == av.NewItemTargetDocument\n}","tryCatchPattern":null,"preventionTips":["Reference the av package constants, never string literals.","Validate against the two-value whitelist before submit.","Upgrade kernel if a newer target type is required."],"tags":["av","new-item-template","target-type","validation","enum"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}