siyuan-note/siyuan · error

recursive template call

Error message

recursive template call [%s] is not supported

What it means

The pre-execution call-graph validator rejects template hierarchies in which a definition calls itself (directly or transitively), because Go's text/template would recurse infinitely at ExecuteTemplate time. validateTemplateCallGraph walks {{template "x"}} references via collectCalledTemplateNames and errors when it re-enters a definition already on the current visiting stack.

Solutions

  1. Find the definition named in the error and remove the {{template "..."}} call that closes the cycle
  2. Unroll recursion into an explicit fixed nesting depth (manually repeated includes)
  3. Refactor shared content into a separate leaf definition that both sides call without referencing each other
  4. Re-run the doc-tree creation after restructuring; validation runs before execution so the fix is safe to iterate

Example fix

// before
define "a" -> {{template "b"}}
define "b" -> {{template "a"}}
// after
define "a" -> {{template "leaf"}}
define "b" -> {{template "leaf"}}
Defensive patterns

Strategy: validation

Validate before calling

// scan {{define}} bodies for {{template "x"}} refs and assert no cycles before install
refs := map[string][]string{ /* name -> called names */ }

Try / catch

if err := validateTemplateCallGraph(root, start); err != nil { return err }

Prevention

When it happens

Trigger: Triggered during renderTemplateDocTreeNodeContent (both the root Define path at line 75 and the child Template path at line 97) when the template graph contains a cycle: definition A invokes B and B invokes A, or a definition invokes itself.

Common situations: Template authors building recursive structures (nested trees, recursive lists) as they would in other template engines that permit recursion, or copy-pasting a shared header into a definition that is itself included.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/438e45c3ee237333. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/template_doc_tree_render.go:112

	if nil != err {
		return nil, fmt.Errorf(Conf.Language(44), err.Error())
	}
	if err = validateTemplateCallGraph(childTemplate, childTemplate.Name()); nil != err {
		return nil, err
	}
	if err = childTemplate.Execute(buf, dataModel); nil != err {
		return nil, fmt.Errorf(Conf.Language(44), err.Error())
	}
	return buf.Bytes(), nil
}

func validateTemplateCallGraph(root *template.Template, start string) error {
	visiting := map[string]bool{}
	depths := map[string]int{}
	var visit func(string) (int, error)
	visit = func(name string) (int, error) {
		if visiting[name] {
			return 0, fmt.Errorf("recursive template call [%s] is not supported", name)
		}
		if depth, ok := depths[name]; ok {
			return depth, nil
		}
		tmpl := root.Lookup(name)
		if nil == tmpl || nil == tmpl.Tree || nil == tmpl.Tree.Root {
			return 0, fmt.Errorf("template definition [%s] not found", name)
		}
		visiting[name] = true
		depth := 1
		for _, called := range collectCalledTemplateNames(tmpl.Tree.Root) {
			calledDepth, err := visit(called)
			if nil != err {
				return 0, err
			}
			if depth < calledDepth+1 {
				depth = calledDepth + 1
			}

View on GitHub (pinned to 9f775e8a12)