siyuan-note/siyuan · error
new item templates config is nil
Error message
new item templates config is nil
What it means
SetNewItemTemplates validates and replaces the database's new-item template configuration. A nil config argument is rejected outright because there is nothing valid to install — clearing templates must use an explicit empty config instead.
Solutions
- Pass a non-nil &NewItemTemplatesConfig{}, e.g. with Templates: []*NewItemTemplate{} to clear all templates.
- Check the pointer for nil at the call site and convert it to an empty config.
- When reading config from a request, default an absent object to an empty struct before calling.
Example fix
// before
av.SetNewItemTemplates(nil)
// after
av.SetNewItemTemplates(&av.NewItemTemplatesConfig{Templates: []*av.NewItemTemplate{}}) Defensive patterns
Strategy: validation
Validate before calling
if cfg == nil {
cfg = &av.NewItemTemplatesConfig{}
} Type guard
func validTemplatesConfig(c *av.NewItemTemplatesConfig) bool { return c != nil } Prevention
- Never pass nil to SetNewItemTemplates; use an empty struct to clear templates
- Default missing JSON payloads to an empty config struct at deserialization
- Add a nil-check helper around all config-mutating AV APIs
When it happens
Trigger: Calling av.AttributeView.SetNewItemTemplates(nil), typically when the caller builds the config from optional JSON fields that were all absent.
Common situations: API/plugin payload missing the templates object; deserializing an empty JSON body into a typed pointer yielding nil; refactored code passing a possibly-nil pointer without a check.
Related errors
- attribute view drop target changed; retry the drag
- attribute view embedded base is missing
- attribute view groups changed; retry the drag
- attribute view instance is not set
- attribute view item markdown is nil
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/258982342a32c48c.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/av/new_item_template.go:40
"sort"
"strings"
"github.com/88250/lute/ast"
"github.com/siyuan-note/siyuan/kernel/util"
)
// PrunedNewItemTemplateOption 描述创建条目前从模板字段值中移除的无效选项。
type PrunedNewItemTemplateOption struct {
TemplateID string
KeyID string
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 {View on GitHub (pinned to 9f775e8a12)