{"record":{"id":"c1d9f0ffa04867a0","repo":"siyuan-note/siyuan","slug":"new-item-template-name-is-empty","errorCode":null,"errorMessage":"new item template name is empty","messagePattern":"new item template name is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/new_item_template.go","lineNumber":64,"sourceCode":"\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)\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)","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/av/new_item_template.go#L46-L82","documentation":"After TrimSpace the template's Name is empty. Name is the display label shown in the 'new item' picker for both detached and document target types, so an empty name is rejected before any further validation.","triggerScenarios":"User saves a template from the AV UI with a blank or whitespace-only name; a JSON import / direct API call posts a template object whose Name field is missing or empty.","commonSituations":"Frontend form submits before the user types a name; import pipeline that drops the Name field; copy-paste of a template definition that omitted the label.","solutions":["Enter a non-empty visible name before saving.","If importing, populate Name for every template entry.","Validate Name client-side and disable the Save button until non-empty."],"exampleFix":"// before\n&av.NewItemTemplate{Name: \"   \", ID: \"...\"}\n// after\n&av.NewItemTemplate{Name: \"Default\", ID: \"...\"}","handlingStrategy":"validation","validationCode":"// Trim and check before submitting.\nname := strings.TrimSpace(t.Name)\nif name == \"\" {\n    return errors.New(\"new item template name is empty\")\n}\nt.Name = name","typeGuard":null,"tryCatchPattern":"if err := attrView.SetNewItemTemplates(config); err != nil {\n    if strings.Contains(err.Error(), \"name is empty\") {\n        // prompt the user for a name, then retry\n    }\n    return err\n}","preventionTips":["Disable Save in the UI until Name has visible content.","Trim whitespace client-side before submit.","Reject imports missing the Name field."],"tags":["av","new-item-template","validation","required-field"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}