{"record":{"id":"84c1a9d241823068","repo":"siyuan-note/siyuan","slug":"template-output-exceeds-d-bytes","errorCode":null,"errorMessage":"template output exceeds %d bytes","messagePattern":"template output exceeds (.+?) bytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template.go","lineNumber":914,"sourceCode":"\ttpl, err := goTpl.Funcs(tplFuncMap).Parse(gulu.Str.FromBytes(md))\n\tif err != nil {\n\t\terr = fmt.Errorf(Conf.Language(44), err.Error())\n\t\treturn\n\t}\n\tif collector.enabled && templateUsesFunction(tpl, \"createDocTree\") {\n\t\tif err = validateTemplateCallGraph(tpl, tpl.Name()); nil != err {\n\t\t\treturn\n\t\t}\n\t}\n\n\tbuf := &bytes.Buffer{}\n\tbuf.Grow(4096)\n\tif err = tpl.Execute(buf, dataModel); err != nil {\n\t\terr = fmt.Errorf(Conf.Language(44), err.Error())\n\t\treturn\n\t}\n\tif 0 < len(collector.nodes) && maxTemplateDocTreeOutputSize < buf.Len() {\n\t\terr = fmt.Errorf(\"template output exceeds %d bytes\", maxTemplateDocTreeOutputSize)\n\t\treturn\n\t}\n\tcollector.totalOutput = buf.Len()\n\tmd = buf.Bytes()\n\ttree, err = parseTemplateKTree(md)\n\tif err != nil {\n\t\tlogging.LogErrorf(\"parse template [%s] failed: %s\", p, err)\n\t\treturn\n\t}\n\ttree.Box = sourceTree.Box\n\tif 0 < len(collector.nodes) {\n\t\tif err = collector.validateLocations(); nil != err {\n\t\t\treturn\n\t\t}\n\t\tif templateTreeContainsAttributeView(tree) {\n\t\t\terr = errors.New(\"database blocks are not supported by createDocTree templates\")\n\t\t\treturn\n\t\t}","sourceCodeStart":896,"sourceCodeEnd":932,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template.go#L896-L932","documentation":"When a template uses createDocTree (collector.enabled) and the rendered output buffer exceeds maxTemplateDocTreeOutputSize, rendering is aborted with this error to bound memory/output of doc-tree generating templates. It only fires when the collector actually produced doc-tree nodes.","triggerScenarios":"renderTemplateSource after Execute: len(collector.nodes) > 0 and buf.Len() > maxTemplateDocTreeOutputSize — i.e. a createDocTree template whose expanded output is huge (e.g. createDocTree over a query returning thousands of blocks).","commonSituations":"A template that queries a very large notebook and creates a document tree per result; recursive/looping query expansion; running the template against test data much larger than when it was written.","solutions":["Narrow the template's query (add LIMIT / filters) so createDocTree produces fewer nodes.","Split the generation into multiple smaller template runs.","If the limit is genuinely too small for your workload, increase maxTemplateDocTreeOutputSize in the kernel and rebuild."],"exampleFix":"// before (template body)\n{{ range .ltsNodes }}{{ createDocTree . \"parent-id\" }}{{ end }}\n// after\n{{ range first 100 .ltsNodes }}{{ createDocTree . \"parent-id\" }}{{ end }}","handlingStrategy":"try-catch","validationCode":"// estimate output size before rendering by counting collector input\nif len(queryResults) > 1000 { warn(\"createDocTree output may exceed limit\") }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.HasPrefix(err.Error(), \"template output exceeds\") {\n    return shrinkQueryAndRetry(templateID)\n}","preventionTips":["Add LIMIT/filters to queries feeding createDocTree","Generate large doc trees in batches instead of one render"],"tags":["go","template","size-limit","output"],"backgroundTag":"file-size-limit-exceeded","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"}