siyuan-note/siyuan · error
Parse template failed: %s
Error message
Parse template failed: %s
What it means
Returned by RenderTemplate when the content template parses fine but fails to EXECUTE against dataModel (template.go:417). Message is Conf.Language(44). dataModel includes title/id/name/alias (and conditionally more). Execution errors come from runtime func failures, nil dereferences, or SQL func errors against the box database.
Source
Thrown at kernel/model/template.go:417
dataModel["id"] = block.ID
dataModel["name"] = block.Name
dataModel["alias"] = block.Alias
}
goTpl := template.New("").Delims(".action{", "}")
tplFuncMap := filesys.BuiltInTemplateFuncs()
sql.SQLTemplateFuncs(&tplFuncMap, tree.Box)
goTpl = goTpl.Funcs(tplFuncMap)
tpl, err := goTpl.Funcs(tplFuncMap).Parse(gulu.Str.FromBytes(md))
if err != nil {
err = fmt.Errorf(Conf.Language(44), err.Error())
return
}
buf := &bytes.Buffer{}
buf.Grow(4096)
if err = tpl.Execute(buf, dataModel); err != nil {
err = fmt.Errorf(Conf.Language(44), err.Error())
return
}
md = buf.Bytes()
tree = parseKTree(md)
if nil == tree {
msg := fmt.Sprintf("parse tree [%s] failed", p)
logging.LogError(msg)
err = errors.New(msg)
return
}
var nodesNeedAppendChild, unlinks []*ast.Node
// 模板内部块旧 ID 到新 ID 的映射,用于成套改写模板内部的自引用
blockIDs := map[string]string{}
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {
return ast.WalkContinue
}View on GitHub (pinned to 251596fc0d)
Solutions
- Read the wrapped inner error (%s) — it identifies the failing function or nil dereference.
- For sql.* funcs, ensure the notebook (tree.Box) is fully indexed before inserting the template.
- Limit field access to keys present in dataModel (title, id, name, alias, plus block-derived vars).
- Use the 'default' template func to guard empty values.
Example fix
// before — sql func fails on unindexed box
.action{sql "SELECT ..."}
// after — index box first, or guard output
.action{sql "SELECT ..." | default "(indexing)"} Defensive patterns
Strategy: try-catch
Try / catch
tree, dom, err := model.RenderTemplate(p, id, preview)
if err != nil {
if strings.Contains(err.Error(), Conf.Language(44)) {
// template execution failure; show the inner cause to the user
}
return handleTemplateError(err)
} Prevention
- Ensure the target notebook is fully indexed before inserting templates that call sql.* funcs.
- Keep field access limited to keys present in dataModel.
- Guard empty values with the 'default' template func.
When it happens
Trigger: A .action{} action calls a sql.* function that fails because the notebook is not indexed or the query is malformed; an action accesses a missing dataModel key; a built-in func receives wrong argument types that pass parse-time checks but fail at execution.
Common situations: Inserting a template that runs sql.* queries right after opening a notebook before indexing completes; a template referencing .action{.someKey} not in the model; a date/format func error on empty input.
Related errors
- Conf.Language(44) {err.Error()}
- execute template [%s] failed: %s
- Conf.Language(132)
- parse template [%s] failed: %s
- appearance files not found at [%s]
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/3e3558425ba5ad63.
Report an issue: GitHub.