siyuan-note/siyuan · error
template document tree output exceeds
Error message
template document tree output exceeds %d bytes
What it means
renderTemplateDocTreeNodes accumulates the rendered byte size of every node's content in collector.totalOutput and enforces maxTemplateDocTreeOutputSize across the whole render. When the aggregate output would exceed that limit, rendering is aborted with this error to bound memory use and prevent runaway templates from generating an unbounded number/size of documents.
Solutions
- Split the template into smaller batches and render/attach multiple smaller plans
- Trim the template content: remove large blocks, reduce loop iterations, or paginate the data source
- Raise maxTemplateDocTreeOutputSize only if the deployment genuinely needs bigger renders (memory tradeoff)
- Check the rendered output size of each node during development and cap data inputs before rendering
Example fix
// before: one giant plan
renderTemplateDocTreeNodes(collector, rootTemplate, funcs) // exceeds limit
// after: batch nodes
for batch := range chunkNodes(collector.nodes, 50) {
renderBatch(batch, rootTemplate, funcs)
} Defensive patterns
Strategy: validation
Validate before calling
const maxTemplateDocTreeOutputSize = 10 * 1024 * 1024 // adjust per repo constant
if estimatedTotalBytes(nodes) > maxTemplateDocTreeOutputSize {
return errors.New("render would exceed output limit; batch the template")
} Try / catch
content, err := renderTemplateDocTreeNodes(collector, rootTemplate, funcs)
if err != nil && strings.Contains(err.Error(), "output exceeds") {
return retryWithSmallerBatch(ctx, remainingNodes)
} Prevention
- Estimate rendered size from the data source before rendering
- Batch large data sets into multiple smaller template plans
- Avoid range loops over unbounded collections in templates
When it happens
Trigger: Rendering a template doc tree whose nodes collectively render more than maxTemplateDocTreeOutputSize bytes — e.g. a root template with many child nodes, loops over large data sets, or templates that inline huge content blocks per node.
Common situations: Very large imported data sets fed via .action{range} loops; recursive nesting of child templates each emitting large content; accidentally rendering an entire large collection into the document tree in one pass.
Understand the failure class
Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.
Related errors
- attribute view [ ] not found in box [ ]
- attribute view [ ] template plan not found
- child template definition
- child template [ ] not found in the current template package
- Conf.Language(44), err.Error()
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/04347afcfc9f0d5b.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_doc_tree_render.go:45
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/siyuan-note/siyuan/kernel/av"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
)
func renderTemplateDocTreeNodes(collector *templateDocTreeCollector, rootTemplate *template.Template,
funcs template.FuncMap) error {
for _, node := range flattenTemplateDocTreeNodes0(collector.nodes) {
content, err := renderTemplateDocTreeNodeContent(collector, rootTemplate, funcs, node)
if nil != err {
return err
}
collector.totalOutput += len(content)
if maxTemplateDocTreeOutputSize < collector.totalOutput {
return fmt.Errorf("template document tree output exceeds %d bytes", maxTemplateDocTreeOutputSize)
}
tree, err := renderTemplateDocTreeMarkdown(content, collector.boxID)
if nil != err {
return err
}
collector.buildTree(node, tree)
}
return nil
}
func renderTemplateDocTreeNodeContent(collector *templateDocTreeCollector, rootTemplate *template.Template,
funcs template.FuncMap, node *TemplateDocTreeNode) ([]byte, error) {
if "" == node.Template && "" == node.Define {
return nil, nil
}
previousAllowCreation := collector.allowCreation
collector.allowCreation = falseView on GitHub (pinned to 9f775e8a12)