{"record":{"id":"3d1fd87b377ba866","repo":"gohugoio/hugo","slug":"s-w-3d1fd8","errorCode":null,"errorMessage":"%s: %w","messagePattern":"%s: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/tplimpl/templatestore.go","lineNumber":989,"sourceCode":"\t\t\t\t\treturn 0\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn 0\n\t\t}\n\n\t\tf, err := fi.Meta().Open()\n\t\tif err != nil {\n\t\t\treturn -1, inErr\n\t\t}\n\t\tdefer f.Close()\n\n\t\tfe := herrors.NewFileErrorFromName(inErr, fi.Meta().Filename)\n\t\tfe.UpdateContent(f, lineMatcher)\n\n\t\treturn matchWeight, fe\n\t}\n\n\tinerr = fmt.Errorf(\"%s: %w\", what, inerr)\n\n\tvar (\n\t\terr1    error\n\t\tweight1 int\n\t\terr2    error\n\t\tweight2 int\n\t)\n\n\tweight1, err1 = checkFilename(ti.Fi, inerr)\n\n\tif ti.base != nil {\n\t\tweight2, err2 = checkFilename(ti.base.Fi, inerr)\n\t}\n\n\tif err2 != nil && weight2 > weight1 {\n\t\treturn err2\n\t}\n","sourceCodeStart":971,"sourceCodeEnd":1007,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/tplimpl/templatestore.go#L971-L1007","documentation":"This is an error-enrichment wrapper in addFileContext (templatestore.go:989). When a template execution fails, Hugo prepends a 'what' description (e.g. 'execute of template failed') to the underlying error via fmt.Errorf(\"%s: %w\", what, inerr), then attempts to attach file/line context. The %s is the action description and %w preserves the original cause for unwrapping. It is the common envelope around template execution failures, not a distinct failure mode itself.","triggerScenarios":"Any template execution error (bad function call, type mismatch, nil dereference in a template pipe, missing partial during execution) flowing through ExecuteWithContext -> addFileContext at templatestore.go:550.","commonSituations":"Calling a non-existent template function; passing the wrong type to a Hugo function inside a template; referencing .Params on a nil page; any runtime template error during `hugo`/`hugo server`.","solutions":["Read the wrapped error (the %w portion) to find the true root cause; the %s prefix is only context.","Use the file/line info Hugo attaches to locate the offending template line.","Reproduce with `hugo --templateMetricsHints` or verbose logging for more detail.","Fix the underlying template error indicated by the wrapped cause."],"exampleFix":"// before — template references undefined method\n{{ .Page.NonExistentMethod }}\n\n// after — use a valid field/method with a guard\n{{ with .Page.Title }}{{ . }}{{ end }}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// When calling Hugo programmatically (hugolib.Test or library use),\n// wrap the build and unwrap to reach the root cause:\nif err := b.Build(BuildCfg{}); err != nil {\n    // errors.Is/As to unwrap the %w chain to the original parse/exec error\n    var fe *herrors.FileError\n    if errors.As(err, &fe) {\n        log.Printf(\"template error at %s:%d: %v\", fe.File().Filename(), fe.LineNumber(), fe)\n    }\n}","preventionTips":["Always read the wrapped (%w) cause, not just the prefix.","Use Hugo's file/line annotations to jump to the offending template line.","Run `hugo --templateMetricsHints` to spot costly/broken templates."],"tags":["template","execution","error-wrapper","build","context"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}