{"record":{"id":"776025ca4a82aa35","repo":"siyuan-note/siyuan","slug":"template-call-depth-exceeds-d","errorCode":null,"errorMessage":"template call depth exceeds %d","messagePattern":"template call depth exceeds (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree_render.go","lineNumber":141,"sourceCode":"\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}\n\t\t}\n\t\tdelete(visiting, name)\n\t\tdepths[name] = depth\n\t\treturn depth, nil\n\t}\n\tdepth, err := visit(start)\n\tif nil != err {\n\t\treturn err\n\t}\n\tif maxTemplateCallDepth < depth {\n\t\treturn fmt.Errorf(\"template call depth exceeds %d\", maxTemplateCallDepth)\n\t}\n\treturn nil\n}\n\nfunc collectCalledTemplateNames(node templateparse.Node) (ret []string) {\n\tif nil == node {\n\t\treturn nil\n\t}\n\tswitch typed := node.(type) {\n\tcase *templateparse.ListNode:\n\t\tif nil == typed {\n\t\t\treturn nil\n\t\t}\n\t\tfor _, child := range typed.Nodes {\n\t\t\tret = append(ret, collectCalledTemplateNames(child)...)\n\t\t}\n\tcase *templateparse.TemplateNode:\n\t\tif nil == typed {","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree_render.go#L123-L159","documentation":"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.","triggerScenarios":"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.","commonSituations":"Elaborate template packages that layer many wrapper definitions (page -> section -> block -> inline), often built incrementally over time until the chain silently exceeds the limit.","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"],"exampleFix":"// before: page -> section -> block -> inline (4 levels)\n// after: page -> block (inline content directly in block)\n{{define \"block\"}}...{{template \"inline\"}}...{{end}}","handlingStrategy":"validation","validationCode":"depth := maxNestingDepth(calls); if depth > maxTemplateCallDepth { /* reject */ }","typeGuard":null,"tryCatchPattern":"if err := validateTemplateCallGraph(root, start); err != nil { return err }","preventionTips":["Keep include chains shallow — prefer flat sibling definitions","Inline trivial wrappers instead of stacking layers","Count nesting depth when composing large template packages"],"tags":["template","depth-limit","validation","recursion-guard"],"backgroundTag":"value-out-of-range","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"}