{"record":{"id":"68f6d1a192cb4fc2","repo":"gohugoio/hugo","slug":"failed-to-parse-empty-text-template-q-w","errorCode":null,"errorMessage":"failed to parse empty text template %q: %w","messagePattern":"failed to parse empty text template %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/tplimpl/templatestore.go","lineNumber":927,"sourceCode":"\n\t\tif best.isBetter(weight, vv) {\n\t\t\tbest.updateValues(weight, k2, k.d, vv)\n\t\t}\n\t}\n}\n\nfunc (t *TemplateStore) addDeferredTemplate(owner *TemplInfo, name string, n *parse.ListNode) error {\n\tif _, found := t.templatesByPath.Get(name); found {\n\t\treturn nil\n\t}\n\n\tvar templ tpl.Template\n\n\tif owner.D.IsPlainText {\n\t\tprototype := t.tns.parseText\n\t\ttt, err := prototype.New(name).Parse(\"\")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to parse empty text template %q: %w\", name, err)\n\t\t}\n\t\ttt.Tree.Root = n\n\t\ttempl = tt\n\t} else {\n\t\tprototype := t.tns.parseHTML\n\t\ttt, err := prototype.New(name).Parse(\"\")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to parse empty HTML template %q: %w\", name, err)\n\t\t}\n\t\ttt.Tree.Root = n\n\t\ttempl = tt\n\t}\n\n\tt.templatesByPath.Set(name, &TemplInfo{\n\t\tFi:       owner.Fi,\n\t\tPathInfo: owner.PathInfo,\n\t\tD:        owner.D,\n\t\tTemplate: templ,","sourceCodeStart":909,"sourceCodeEnd":945,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/tplimpl/templatestore.go#L909-L945","documentation":"When Hugo registers a deferred text template (via addDeferredTemplate, templatestore.go:916-927), it parses an empty string with the text template prototype as a seed and then swaps in the deferred node list. If that empty-string parse fails (prototype.New(name).Parse(\"\")), the error wraps the underlying parse error. An empty parse failing is an exceptional/internal condition since the input is the literal empty string.","triggerScenarios":"Triggered internally when processing templates that use Hugo's deferred rendering (e.g. {{ doDefer ... }} or pagination/defer blocks) and the text template prototype is in a corrupt or unexpectedly-modified state. This is not a user-content-driven error under normal Hugo internals.","commonSituations":"Almost never seen in normal use because parsing an empty string should always succeed. Could surface if a custom fork modifies the prototype template or injects broken funcs, or in edge cases with conflicting template namespaces during development of Hugo itself.","solutions":["If seen in a standard Hugo build, report it as a Hugo bug with the template name from the error.","Check for any custom code that mutates the parseText prototype template.","Update to the latest Hugo patch release to pick up fixes to the deferred-template machinery.","Isolate which content/template triggers it by bisecting recently added layouts."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// This is an internal Hugo error. In Hugo's Go tests, treat any build error\n// matching this message as a fatal/internal failure:\nif strings.Contains(err.Error(), \"failed to parse empty text template\") {\n    t.Fatalf(\"internal Hugo template error: %v\", err)\n}","preventionTips":["Do not modify Hugo's internal text template prototype.","Keep Hugo updated to benefit from deferred-template fixes.","Report reproducible occurrences upstream with the template name."],"tags":["template","deferred","internal","parse-error","plaintext"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}