siyuan-note/siyuan · error
invalid new item template target type [%s]
Error message
invalid new item template target type [%s]
What it means
TargetType must be exactly NewItemTargetDetached or NewItemTargetDocument — the two valid creation targets for a new AV row (a detached block vs. a full document). Any other value, including the empty string, is rejected before the icon/hide-in-tree normalization that depends on the target.
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 251596fc0d)
Solutions
- Send one of the two canonical constants defined in the av package.
- If a newer target type is required, upgrade the kernel to a version that supports it.
- Validate TargetType against the whitelist on the client before submission.
Example fix
// before
&av.NewItemTemplate{TargetType: "doc"}
// after
&av.NewItemTemplate{TargetType: av.NewItemTargetDocument} Defensive patterns
Strategy: type-guard
Type guard
func isValidTargetType(t string) bool {
return t == av.NewItemTargetDetached || t == av.NewItemTargetDocument
} Prevention
- Reference the av package constants, never string literals.
- Validate against the two-value whitelist before submit.
- Upgrade kernel if a newer target type is required.
When it happens
Trigger: Frontend sends a stale or misspelled target constant; a future client introduces a new target type the running kernel does not recognize yet; manual API call with an arbitrary string.
Common situations: Version skew between frontend and kernel; typo in mode string; import authored against a newer schema.
Related errors
- invalid new item template field value mode [%s]
- new item templates config is nil
- new item template name is empty
- invalid new item template id [%s]
- duplicated new item template id [%s]
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/9febd4410c3dfe67.
Report an issue: GitHub.