{"record":{"id":"49ed9dfe09c4c9c5","repo":"siyuan-note/siyuan","slug":"template-source-is-too-large","errorCode":null,"errorMessage":"template source is too large","messagePattern":"template source is too large","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template.go","lineNumber":743,"sourceCode":"\tmdTableHead.AppendChild(mdTableHeadRow)\n\tfor _, col := range table.Columns {\n\t\tcell := &ast.Node{Type: ast.NodeTableCell}\n\t\tcell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(col.Name)})\n\t\tmdTableHeadRow.AppendChild(cell)\n\t}\n\tnode.InsertBefore(mdTable)\n\treturn mdTable\n}\n\nfunc RenderTemplateWithMode(p, id string, mode TemplateRenderMode) (tree *parse.Tree, dom string,\n\tsummary *TemplateDocTreePlanSummary, err error) {\n\treturn renderTemplateSource(p, id, mode, nil)\n}\n\n// 编辑器预览使用未保存的源码，文件路径仅用于解析同包子模板。\nfunc PreviewTemplateSource(p, id, content string) (tree *parse.Tree, dom string, summary *TemplateDocTreePlanSummary, err error) {\n\tif len(content) > maxTemplateSourceSize {\n\t\treturn nil, \"\", nil, errors.New(\"template source is too large\")\n\t}\n\treturn renderTemplateSource(p, id, TemplateRenderModePreview, &content)\n}\n\nfunc renderTemplateSource(p, id string, mode TemplateRenderMode, content *string) (tree *parse.Tree, dom string,\n\tsummary *TemplateDocTreePlanSummary, err error) {\n\tif TemplateRenderModeContent != mode && TemplateRenderModePreview != mode && TemplateRenderModeEditorInsert != mode {\n\t\terr = fmt.Errorf(\"unsupported template render mode [%s]\", mode)\n\t\treturn\n\t}\n\tpreview := TemplateRenderModePreview == mode\n\ttree, err = LoadTreeByBlockID(id)\n\tif err != nil {\n\t\treturn\n\t}\n\tsourceTree := tree\n\n\tnode := treenode.GetNodeInTree(tree, id)","sourceCodeStart":725,"sourceCodeEnd":761,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/template.go#L725-L761","documentation":"PreviewTemplateSource rejects template sources larger than maxTemplateSourceSize (8 MiB) before parsing, to bound memory and CPU spent on preview rendering. The content string passed by the editor exceeded this hard limit.","triggerScenarios":"Calling PreviewTemplateSource with a content string longer than 8*1024*1024 bytes; pasting a huge document into the template editor and triggering preview.","commonSituations":"Pasting an entire large notebook export into a template; a plugin generating enormous template content programmatically; binary data accidentally embedded in the template text.","solutions":["Reduce the template source below 8 MiB — split it into multiple templates or use sub-template includes","Trim pasted content to the needed snippet before previewing","If handling large documents, render them via document-tree mechanisms (createDocTree) instead of inlining everything in one template"],"exampleFix":"// before: previewing full 20 MB content\nPreviewTemplateSource(box, id, hugeContent)\n// after: guard before calling\nif len(content) <= 8*1024*1024 { PreviewTemplateSource(box, id, content) }","handlingStrategy":"validation","validationCode":"const maxTemplateSourceSize = 8 * 1024 * 1024\nif len(content) > maxTemplateSourceSize {\n    return errors.New(\"template content exceeds 8 MiB preview limit\")\n}","typeGuard":null,"tryCatchPattern":"tree, dom, summary, err := PreviewTemplateSource(p, id, content)\nif err != nil && strings.Contains(err.Error(), \"too large\") {\n    // truncate or split the source before retrying\n}","preventionTips":["Check content length before calling PreviewTemplateSource","Split oversized templates into smaller files or use sub-templates","Avoid pasting whole documents into template editors"],"tags":["go","template","size-limit","preview"],"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"}