{"record":{"id":"172b6c0adb710d11","repo":"siyuan-note/siyuan","slug":"template-source-is-too-large-172b6c","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_manage.go","lineNumber":141,"sourceCode":"\th := sha256.New()\n\tif info.IsDir() {\n\t\terr = fs.WalkDir(root.FS(), p, func(name string, entry fs.DirEntry, walkErr error) error {\n\t\t\tif walkErr != nil {\n\t\t\t\treturn walkErr\n\t\t\t}\n\t\t\tstat, statErr := entry.Info()\n\t\t\tif statErr != nil {\n\t\t\t\treturn statErr\n\t\t\t}\n\t\t\tif stat.Mode()&os.ModeSymlink != 0 {\n\t\t\t\treturn errors.New(\"template directory contains a symbolic link\")\n\t\t\t}\n\t\t\tfmt.Fprintf(h, \"%s\\x00%d\\x00%d\\x00%d\\n\", name, stat.Size(), stat.ModTime().UnixNano(), stat.Mode())\n\t\t\treturn nil\n\t\t})\n\t} else {\n\t\tif info.Size() > maxTemplateSourceSize {\n\t\t\treturn \"\", errors.New(\"template source is too large\")\n\t\t}\n\t\tvar content []byte\n\t\tcontent, err = root.ReadFile(p)\n\t\th.Write(content)\n\t}\n\treturn fmt.Sprintf(\"%x\", h.Sum(nil)), err\n}\n\nfunc readTemplateSource(root *os.Root, p string) (string, error) {\n\tinfo, err := root.Stat(p)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tif !info.Mode().IsRegular() || info.Size() > maxTemplateSourceSize {\n\t\treturn \"\", errors.New(\"invalid template source file\")\n\t}\n\tcontent, err := root.ReadFile(p)\n\tif err != nil {","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_manage.go#L123-L159","documentation":"templateFileRevision enforces maxTemplateSourceSize on single template files before reading them into the revision hash; exceeding the cap returns this error. The limit protects memory and hashing cost when templates grow unexpectedly large.","triggerScenarios":"ManageTemplateFiles computing a revision for a template file whose size exceeds maxTemplateSourceSize.","commonSituations":"Pasting huge documents as templates, template files accidentally containing embedded base64 assets or exported data, or a log/data file dropped into the templates folder.","solutions":["Shrink the template file — move large assets out and reference them instead","Split the content into multiple smaller templates","Remove non-template files from the templates directory"],"exampleFix":"# before: templates/huge.md contains a 100MB embedded attachment\n# after: templates/huge.md links to the asset stored outside the template body","handlingStrategy":"validation","validationCode":"if info, err := os.Stat(p); err == nil && info.Size() > maxTemplateSourceSize { /* refuse before calling */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep templates small; externalize large assets","Monitor the templates directory for accidentally dumped large files"],"tags":["file-size","limits","templates"],"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"}