{"record":{"id":"03c6a98010f1502b","repo":"siyuan-note/siyuan","slug":"default-new-item-template-s-not-found","errorCode":null,"errorMessage":"default new item template [%s] not found","messagePattern":"default new item template \\[(.+?)\\] not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/new_item_template.go","lineNumber":91,"sourceCode":"\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}\n\tif 0 == len(templates) {\n\t\tav.NewItemTemplates = nil\n\t} else {\n\t\tav.NewItemTemplates = templates\n\t}\n\tav.DefaultTemplateID = defaultTemplateID\n\treturn nil\n}\n\n// GetNewItemTemplate 根据 ID 获取新增条目模板。\nfunc (av *AttributeView) GetNewItemTemplate(id string) *NewItemTemplate {\n\tfor _, itemTemplate := range av.NewItemTemplates {\n\t\tif nil != itemTemplate && itemTemplate.ID == id {\n\t\t\treturn itemTemplate\n\t\t}\n\t}\n\treturn nil","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/new_item_template.go#L73-L109","documentation":"After validating all templates, SetNewItemTemplates verifies that config.DefaultTemplateID, when non-empty, refers to one of the template IDs in the same config. If the default template ID does not exist among the supplied templates, the configuration is rejected and the attribute view's templates are left unchanged.","triggerScenarios":"Calling SetNewItemTemplates with a DefaultTemplateID that is not present (or was renamed/removed) in config.Templates, or whose ID was changed after the default was recorded.","commonSituations":"Deleting or renaming a template but leaving it as the default in saved settings; plugins restoring a config snapshot where DefaultTemplateID references a template that no longer exists; empty-string vs stale ID handling after clearing all templates.","solutions":["Set config.DefaultTemplateID to the exact ID of one of the templates in config.Templates","Leave DefaultTemplateID as an empty string if no default template is intended","Sync the default ID whenever a template's ID changes or the template is deleted"],"exampleFix":"// before\nconfig.DefaultTemplateID = \"20240101120000-abc1234\" // template was deleted\nerr := av.SetNewItemTemplates(config)\n// after\nconfig.DefaultTemplateID = \"\" // or point at an existing template ID\nerr := av.SetNewItemTemplates(config)","handlingStrategy":"validation","validationCode":"if config.DefaultTemplateID != \"\" {\n\tfound := false\n\tfor _, t := range config.Templates {\n\t\tif t != nil && t.ID == config.DefaultTemplateID { found = true; break }\n\t}\n\tif !found { return fmt.Errorf(\"default template %q missing\", config.DefaultTemplateID) }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive DefaultTemplateID from the templates list at save time rather than storing it independently","When deleting a template, clear or reassign DefaultTemplateID in the same operation"],"tags":["attribute-view","validation","referential-integrity"],"backgroundTag":"resource-not-found","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"}