siyuan-note/siyuan · error
template call depth exceeds
Error message
template call depth exceeds %d
What it means
validateTemplateCallGraph computes the longest chain of nested {{template}} calls from the start definition and rejects graphs whose depth exceeds maxTemplateCallDepth. This caps nesting so deeply chained template packages cannot exhaust memory or stack, even though each link individually is legal and acyclic.
Solutions
- Flatten the definition chain by inlining some wrappers or calling leaf content directly
- Split the output into multiple sibling definitions instead of one deep nesting chain
- Reduce one level of indirection per render unit; aim for a shallow, flat hierarchy
- Check the constant maxTemplateCallDepth in the kernel to know the exact allowed limit
Example fix
// before: page -> section -> block -> inline (4 levels)
// after: page -> block (inline content directly in block)
{{define "block"}}...{{template "inline"}}...{{end}} Defensive patterns
Strategy: validation
Validate before calling
depth := maxNestingDepth(calls); if depth > maxTemplateCallDepth { /* reject */ } Try / catch
if err := validateTemplateCallGraph(root, start); err != nil { return err } Prevention
- Keep include chains shallow — prefer flat sibling definitions
- Inline trivial wrappers instead of stacking layers
- Count nesting depth when composing large template packages
When it happens
Trigger: Raised when the computed depth from visit(start) exceeds maxTemplateCallDepth during renderTemplateSource or renderTemplateDocTreeNodeContent: e.g. a chain of definitions A -> B -> C -> ... longer than the allowed maximum.
Common situations: Elaborate template packages that layer many wrapper definitions (page -> section -> block -> inline), often built incrementally over time until the chain silently exceeds the limit.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Conf.Language(118)
- createDocTree document contains unknown field
- createDocTree document
- createDocTree document
- createDocTree document template and define are mutually…
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/776025ca4a82aa35.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_doc_tree_render.go:141
for _, called := range collectCalledTemplateNames(tmpl.Tree.Root) {
calledDepth, err := visit(called)
if nil != err {
return 0, err
}
if depth < calledDepth+1 {
depth = calledDepth + 1
}
}
delete(visiting, name)
depths[name] = depth
return depth, nil
}
depth, err := visit(start)
if nil != err {
return err
}
if maxTemplateCallDepth < depth {
return fmt.Errorf("template call depth exceeds %d", maxTemplateCallDepth)
}
return nil
}
func collectCalledTemplateNames(node templateparse.Node) (ret []string) {
if nil == node {
return nil
}
switch typed := node.(type) {
case *templateparse.ListNode:
if nil == typed {
return nil
}
for _, child := range typed.Nodes {
ret = append(ret, collectCalledTemplateNames(child)...)
}
case *templateparse.TemplateNode:
if nil == typed {View on GitHub (pinned to 9f775e8a12)