siyuan-note/siyuan · error

invalid new item template target type

Error message

invalid new item template target type [%s]

What it means

SetNewItemTemplates validates each new-item template's TargetType and rejects any value that is neither NewItemTargetDetached nor NewItemTargetDocument. The attribute view only supports creating detached rows or new documents from a template, so any other TargetType string is treated as an invalid configuration and the whole SetNewItemTemplates call fails without modifying the view.

Solutions

  1. Set TargetType to the exported constant av.NewItemTargetDetached for detached-row templates
  2. Set TargetType to av.NewItemTargetDocument for document-creating templates
  3. Check the serialized config JSON for a typo or stale value in the target type field and correct it to one of the two supported constants

Example fix

// before
itemTemplate.TargetType = "document"
_ = av.SetNewItemTemplates(config)
// after
itemTemplate.TargetType = av.NewItemTargetDocument
err := av.SetNewItemTemplates(config)
Defensive patterns

Strategy: validation

Validate before calling

if itemTemplate.TargetType != av.NewItemTargetDetached && itemTemplate.TargetType != av.NewItemTargetDocument {
	return fmt.Errorf("unsupported target type %q", itemTemplate.TargetType)
}

Prevention

When it happens

Trigger: Calling AttributeView.SetNewItemTemplates with a config whose Templates[i].TargetType is an unknown/unrecognized value (anything other than the NewItemTargetDetached or NewItemTargetDocument constants, e.g. a typo'd or empty string from hand-built config or a plugin).

Common situations: Plugins or scripts constructing NewItemTemplatesConfig manually with a misspelled TargetType; older persisted configs written before the TargetType constants were stabilized; serialized JSON where the field was deserialized as an unexpected value.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/9febd4410c3dfe67. Report an issue: GitHub.

Appendix: source

Thrown at kernel/av/new_item_template.go:74

		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)
			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)
	}

View on GitHub (pinned to 9f775e8a12)