siyuan-note/siyuan · error
clone new item template failed
Error message
clone new item template failed
What it means
cloneNewItemTemplate returned nil. In the current implementation cloneNewItemTemplate only returns nil when its input is nil (new_item_template.go:469), and the loop above already does `if nil == itemTemplate { continue }`. So through the public API this branch is effectively unreachable; it exists as a defensive guard against a future clone failure mode.
Source
Thrown at kernel/av/new_item_template.go:52
Values []string
}
// SetNewItemTemplates 校验并替换数据库的新增条目模板配置。
func (av *AttributeView) SetNewItemTemplates(config *NewItemTemplatesConfig) error {
if nil == config {
return errors.New("new item templates config is nil")
}
templates := make([]*NewItemTemplate, 0, len(config.Templates))
templateIDs := map[string]bool{}
defaultTemplateID := config.DefaultTemplateID
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)View on GitHub (pinned to 251596fc0d)
Solutions
- If you see this in production, inspect cloneNewItemTemplate for newly added failure paths.
- Report to kernel maintainers with the template payload, since current code cannot produce it.
Defensive patterns
Strategy: validation
Validate before calling
// Defensive: verify clone result before relying on it (mirrors the kernel guard).
cloned := cloneNewItemTemplate(t)
if cloned == nil {
return errors.New("clone new item template failed")
} Prevention
- Treat this error as a kernel bug if observed — current code cannot produce it.
- Pin kernel version when relying on cloneNewItemTemplate in plugins.
When it happens
Trigger: Not reachable via SetNewItemTemplates today. Would only fire if cloneNewItemTemplate grew a new failure path (e.g. deep-copy allocation failure) and returned nil for non-nil input.
Common situations: Should not occur in practice; if it does, suspect a kernel regression in cloneNewItemTemplate or memory pressure during a future deep-copy change.
Related errors
- new item templates config is nil
- new item template name is empty
- invalid new item template id [%s]
- duplicated new item template id [%s]
- invalid new item template target type [%s]
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/e0c4a0dfeb1a8f0f.
Report an issue: GitHub.