siyuan-note/siyuan · error

default new item template [%s] not found

Error message

default new item template [%s] not found

What it means

config.DefaultTemplateID is non-empty but does not match any template ID actually present in config.Templates. The check runs after the per-template loop (new_item_template.go:90), so it also fires when the referenced template was skipped (nil input) or rejected earlier in the loop for a different validation failure.

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 nil

View on GitHub (pinned to 251596fc0d)

Solutions

  1. When removing the default template, clear DefaultTemplateID (set to "") or repoint it to a remaining template's ID before saving.
  2. On the client, recompute the default whenever the template list changes.
  3. If the earlier failure is the real cause, fix the underlying validation error first so the referenced template survives the loop.

Example fix

// before
config.DefaultTemplateID = "deleted-id"
// after
config.DefaultTemplateID = ""
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 new item template [%s] not found", config.DefaultTemplateID)
    }
}

Prevention

When it happens

Trigger: User deletes the template that is currently the default without first clearing DefaultTemplateID; a template failed earlier validation (empty name, bad ID, etc.) leaving the default pointer dangling; UI state out of sync with the backend.

Common situations: Delete-then-save race; client keeps a stale default ID after the user removes that template; sync applying a remote template deletion locally.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/03c6a98010f1502b. Report an issue: GitHub.