siyuan-note/siyuan · error
default new item template
Error message
default new item template [%s] not found
What it means
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.
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
Example fix
// before config.DefaultTemplateID = "20240101120000-abc1234" // template was deleted err := av.SetNewItemTemplates(config) // after config.DefaultTemplateID = "" // or point at an existing template ID err := av.SetNewItemTemplates(config)
Defensive patterns
Strategy: validation
Validate before calling
if config.DefaultTemplateID != "" {
found := false
for _, t := range config.Templates {
if t != nil && t.ID == config.DefaultTemplateID { found = true; break }
}
if !found { return fmt.Errorf("default template %q missing", config.DefaultTemplateID) }
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- new item template field
- at least one visible view is required
- attribute view custom color index
- attribute view custom color must not be null
- attribute view custom colors count exceeds the
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/03c6a98010f1502b.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/av/new_item_template.go:91
if NewItemTargetDetached != itemTemplate.TargetType && NewItemTargetDocument != itemTemplate.TargetType {
return fmt.Errorf("invalid new item template target type [%s]", itemTemplate.TargetType)
}
if NewItemTargetDocument != itemTemplate.TargetType {
itemTemplate.Icon = ""
itemTemplate.HideInFileTree = false
}
itemTemplate.ContentTemplatePath = strings.TrimSpace(itemTemplate.ContentTemplatePath)
if nil != itemTemplate.SaveLocation {
itemTemplate.SaveLocation.BoxID = strings.TrimSpace(itemTemplate.SaveLocation.BoxID)
itemTemplate.SaveLocation.PathTemplate = strings.TrimSpace(itemTemplate.SaveLocation.PathTemplate)
}
if err := av.normalizeNewItemTemplateFieldValues(itemTemplate); nil != err {
return err
}
templates = append(templates, itemTemplate)
}
if "" != defaultTemplateID && !templateIDs[defaultTemplateID] {
return fmt.Errorf("default new item template [%s] not found", defaultTemplateID)
}
if 0 == len(templates) {
av.NewItemTemplates = nil
} else {
av.NewItemTemplates = templates
}
av.DefaultTemplateID = defaultTemplateID
return nil
}
// GetNewItemTemplate 根据 ID 获取新增条目模板。
func (av *AttributeView) GetNewItemTemplate(id string) *NewItemTemplate {
for _, itemTemplate := range av.NewItemTemplates {
if nil != itemTemplate && itemTemplate.ID == id {
return itemTemplate
}
}
return nilView on GitHub (pinned to 9f775e8a12)