{"record":{"id":"04347afcfc9f0d5b","repo":"siyuan-note/siyuan","slug":"template-document-tree-output-exceeds-d-bytes","errorCode":null,"errorMessage":"template document tree output exceeds %d bytes","messagePattern":"template document tree output exceeds (.+?) bytes","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree_render.go","lineNumber":45,"sourceCode":"\n\t\"github.com/88250/lute/ast\"\n\t\"github.com/88250/lute/parse\"\n\t\"github.com/siyuan-note/siyuan/kernel/av\"\n\t\"github.com/siyuan-note/siyuan/kernel/sql\"\n\t\"github.com/siyuan-note/siyuan/kernel/treenode\"\n\t\"github.com/siyuan-note/siyuan/kernel/util\"\n)\n\nfunc renderTemplateDocTreeNodes(collector *templateDocTreeCollector, rootTemplate *template.Template,\n\tfuncs template.FuncMap) error {\n\tfor _, node := range flattenTemplateDocTreeNodes0(collector.nodes) {\n\t\tcontent, err := renderTemplateDocTreeNodeContent(collector, rootTemplate, funcs, node)\n\t\tif nil != err {\n\t\t\treturn err\n\t\t}\n\t\tcollector.totalOutput += len(content)\n\t\tif maxTemplateDocTreeOutputSize < collector.totalOutput {\n\t\t\treturn fmt.Errorf(\"template document tree output exceeds %d bytes\", maxTemplateDocTreeOutputSize)\n\t\t}\n\t\ttree, err := renderTemplateDocTreeMarkdown(content, collector.boxID)\n\t\tif nil != err {\n\t\t\treturn err\n\t\t}\n\t\tcollector.buildTree(node, tree)\n\t}\n\treturn nil\n}\n\nfunc renderTemplateDocTreeNodeContent(collector *templateDocTreeCollector, rootTemplate *template.Template,\n\tfuncs template.FuncMap, node *TemplateDocTreeNode) ([]byte, error) {\n\tif \"\" == node.Template && \"\" == node.Define {\n\t\treturn nil, nil\n\t}\n\n\tpreviousAllowCreation := collector.allowCreation\n\tcollector.allowCreation = false","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/template_doc_tree_render.go#L27-L63","documentation":"renderTemplateDocTreeNodes accumulates the byte length of every rendered template node and enforces maxTemplateDocTreeOutputSize as a hard cap on total generated output. When the aggregate rendered markdown from all nodes exceeds this limit, rendering is aborted with this error to prevent unbounded memory/document growth from a runaway template.","triggerScenarios":"A template document tree whose child templates (node.Template files or node.Define definitions) collectively render more bytes than maxTemplateDocTreeOutputSize — e.g. a .action{range ...} loop over a large dataset inside a child template, or many nodes each rendering large content.","commonSituations":"Range loops iterating thousands of rows in a child template; deeply nested doc-tree templates each emitting large sections; importing a template package designed for a single doc into a multi-node doc tree.","solutions":["Reduce the amount of content the template renders (limit range loops, trim large sections)","Split the template into several smaller template document tree invocations","Cap loop iterations with template logic (e.g. slice/index limits) before rendering","If the limit is legitimately too small for your use case, raise maxTemplateDocTreeOutputSize in the kernel and rebuild"],"exampleFix":"// before\n.action{range .items}...full row content...{.action end}\n// after: cap iterations\n.action{range $i, $v := .items}{if lt $i 100}...row...{end}{end}","handlingStrategy":"validation","validationCode":"const maxTemplateDocTreeOutputSize = 1 << 20 // match kernel constant\nif estimateTemplateOutputBytes(nodes) > maxTemplateDocTreeOutputSize {\n\treturn errors.New(\"template output would exceed the kernel's aggregate output limit\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cap range-loop iterations inside child templates before shipping them","Estimate rendered size (e.g. dry-run render in a test) for large templates","Split very large template document trees into multiple smaller ones"],"tags":["go","template","limits","rendering"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}