{"record":{"id":"438e45c3ee237333","repo":"siyuan-note/siyuan","slug":"recursive-template-call-s-is-not-supported","errorCode":null,"errorMessage":"recursive template call [%s] is not supported","messagePattern":"recursive template call \\[(.+?)\\] is not supported","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree_render.go","lineNumber":112,"sourceCode":"\tif nil != err {\n\t\treturn nil, fmt.Errorf(Conf.Language(44), err.Error())\n\t}\n\tif err = validateTemplateCallGraph(childTemplate, childTemplate.Name()); nil != err {\n\t\treturn nil, err\n\t}\n\tif err = childTemplate.Execute(buf, dataModel); nil != err {\n\t\treturn nil, fmt.Errorf(Conf.Language(44), err.Error())\n\t}\n\treturn buf.Bytes(), nil\n}\n\nfunc validateTemplateCallGraph(root *template.Template, start string) error {\n\tvisiting := map[string]bool{}\n\tdepths := map[string]int{}\n\tvar visit func(string) (int, error)\n\tvisit = func(name string) (int, error) {\n\t\tif visiting[name] {\n\t\t\treturn 0, fmt.Errorf(\"recursive template call [%s] is not supported\", name)\n\t\t}\n\t\tif depth, ok := depths[name]; ok {\n\t\t\treturn depth, nil\n\t\t}\n\t\ttmpl := root.Lookup(name)\n\t\tif nil == tmpl || nil == tmpl.Tree || nil == tmpl.Tree.Root {\n\t\t\treturn 0, fmt.Errorf(\"template definition [%s] not found\", name)\n\t\t}\n\t\tvisiting[name] = true\n\t\tdepth := 1\n\t\tfor _, called := range collectCalledTemplateNames(tmpl.Tree.Root) {\n\t\t\tcalledDepth, err := visit(called)\n\t\t\tif nil != err {\n\t\t\t\treturn 0, err\n\t\t\t}\n\t\t\tif depth < calledDepth+1 {\n\t\t\t\tdepth = calledDepth + 1\n\t\t\t}","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree_render.go#L94-L130","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Find the definition named in the error and remove the {{template \"...\"}} call that closes the cycle","Unroll recursion into an explicit fixed nesting depth (manually repeated includes)","Refactor shared content into a separate leaf definition that both sides call without referencing each other","Re-run the doc-tree creation after restructuring; validation runs before execution so the fix is safe to iterate"],"exampleFix":"// before\ndefine \"a\" -> {{template \"b\"}}\ndefine \"b\" -> {{template \"a\"}}\n// after\ndefine \"a\" -> {{template \"leaf\"}}\ndefine \"b\" -> {{template \"leaf\"}}","handlingStrategy":"validation","validationCode":"// scan {{define}} bodies for {{template \"x\"}} refs and assert no cycles before install\nrefs := map[string][]string{ /* name -> called names */ }","typeGuard":null,"tryCatchPattern":"if err := validateTemplateCallGraph(root, start); err != nil { return err }","preventionTips":["Design template packages as a strict tree, never a graph with back edges","Extract shared content into leaf definitions both callers reference","Never include a definition from itself, directly or transitively"],"tags":["template","recursion","call-graph","validation"],"backgroundTag":"recursive-template-call","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}