siyuan-note/siyuan · error

new item template name is empty

Error message

new item template name is empty

What it means

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.

Source

Thrown at kernel/av/new_item_template.go:64

	for _, itemTemplate := range config.Templates {
		if nil == itemTemplate {
			continue
		}
		itemTemplate = cloneNewItemTemplate(itemTemplate)
		if nil == itemTemplate {
			return errors.New("clone new item template failed")
		}
		itemTemplate.Name = strings.TrimSpace(itemTemplate.Name)
		itemTemplate.Icon = strings.TrimSpace(itemTemplate.Icon)
		if filteredIcon, valid := util.FilterIconValue(itemTemplate.Icon); valid {
			itemTemplate.Icon = filteredIcon
		} else {
			// 非法图标值置空,防止存储可执行标记
			// https://github.com/siyuan-note/siyuan/security/advisories/GHSA-vx5w-qrvp-mmcq
			itemTemplate.Icon = ""
		}
		if "" == itemTemplate.Name {
			return errors.New("new item template name is empty")
		}
		if !ast.IsNodeIDPattern(itemTemplate.ID) {
			return fmt.Errorf("invalid new item template id [%s]", itemTemplate.ID)
		}
		if templateIDs[itemTemplate.ID] {
			return fmt.Errorf("duplicated new item template id [%s]", itemTemplate.ID)
		}
		templateIDs[itemTemplate.ID] = true
		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)

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Enter a non-empty visible name before saving.
  2. If importing, populate Name for every template entry.
  3. Validate Name client-side and disable the Save button until non-empty.

Example fix

// before
&av.NewItemTemplate{Name: "   ", ID: "..."}
// after
&av.NewItemTemplate{Name: "Default", ID: "..."}
Defensive patterns

Strategy: validation

Validate before calling

// Trim and check before submitting.
name := strings.TrimSpace(t.Name)
if name == "" {
    return errors.New("new item template name is empty")
}
t.Name = name

Try / catch

if err := attrView.SetNewItemTemplates(config); err != nil {
    if strings.Contains(err.Error(), "name is empty") {
        // prompt the user for a name, then retry
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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