{"id":"d3b9c83350b57a43","repo":"gohugoio/hugo","slug":"s-resource-err-was-removed-in-hugo-v0-141-0-and","errorCode":null,"errorMessage":"%s: Resource.Err was removed in Hugo v0.141.0 and replaced with a new try keyword, see https://gohugo.io/functions/go-template/try/","messagePattern":"(.+?): Resource\\.Err was removed in Hugo v0\\.141\\.0 and replaced with a new try keyword, see https://gohugo\\.io/functions/go-template/try/","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/hugo_sites_build.go","lineNumber":416,"sourceCode":"// render renders the sites.\nfunc (h *HugoSites) render(l logg.LevelLogger, config *BuildCfg) error {\n\tl = l.WithField(\"step\", \"render\")\n\tstart := time.Now()\n\tdefer func() {\n\t\tloggers.TimeTrackf(l, start, h.buildCounters.loggFields(), \"\")\n\t}()\n\n\tsiteRenderContext := &siteRenderContext{cfg: config, infol: l, multihost: h.Configs.IsMultihost}\n\n\trenderErr := func(err error) error {\n\t\tif err == nil {\n\t\t\treturn nil\n\t\t}\n\t\t// In Hugo 0.141.0 we replaced the special error handling for resources.GetRemote\n\t\t// with the more general try.\n\t\tif strings.Contains(err.Error(), \"can't evaluate field Err in type\") {\n\t\t\tif strings.Contains(err.Error(), \"resource.Resource\") {\n\t\t\t\treturn fmt.Errorf(\"%s: Resource.Err was removed in Hugo v0.141.0 and replaced with a new try keyword, see https://gohugo.io/functions/go-template/try/\", err)\n\t\t\t} else if strings.Contains(err.Error(), \"template.HTML\") {\n\t\t\t\treturn fmt.Errorf(\"%s: the return type of transform.ToMath was changed in Hugo v0.141.0 and the error handling replaced with a new try keyword, see https://gohugo.io/functions/go-template/try/\", err)\n\t\t\t}\n\t\t}\n\t\treturn err\n\t}\n\n\ti := 0\n\n\tfor s := range h.allSites(nil) {\n\t\tif s.conf.Segments.Config.SegmentFilter.ShouldExcludeCoarse(segments.SegmentQuery{Site: s.siteVector}) {\n\t\t\tl.Logf(\"skip site %s not matching segments set in --renderSegments\", s.resolveDimensionNames())\n\t\t\tcontinue\n\t\t}\n\t\tsiteRenderContext.languageIdx = s.siteVector.Language()\n\t\th.currentSite = s\n\t\tfor siteOutIdx, renderFormat := range s.renderFormats {\n\t\t\tif s.conf.Segments.Config.SegmentFilter.ShouldExcludeCoarse(segments.SegmentQuery{Output: renderFormat.Name, Site: s.siteVector}) {","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/hugo_sites_build.go#L398-L434","documentation":"A template accessed `.Err` on a resource.Resource value, a field that was removed in Hugo v0.141.0. Hugo detects the generic template failure 'can't evaluate field Err in type resource.Resource' during render and rewrites it into this actionable message pointing at the replacement `try` keyword for error handling on resources.GetRemote and similar.","triggerScenarios":"Rendering a template containing patterns like `{{ with resources.GetRemote $url }}{{ with .Err }}...{{ end }}{{ end }}` (the pre-0.141 idiom for handling remote fetch errors) on Hugo ≥0.141.0.","commonSituations":"Upgrading Hugo past 0.141.0 with an older theme or copied snippet that used `.Err` to guard resources.GetRemote failures; themes not yet updated for the try keyword.","solutions":["Rewrite the template to use try: `{{ with try (resources.GetRemote $url) }}{{ with .Err }}error{{ else with .Value }}use it{{ end }}{{ end }}` — see https://gohugo.io/functions/go-template/try/.","Update the theme to a version that supports Hugo ≥0.141.0.","As a stopgap, pin Hugo to <0.141.0 until templates are migrated."],"exampleFix":"{{/* before (Hugo < 0.141) */}}\n{{ with resources.GetRemote $url }}\n  {{ with .Err }}{{ errorf \"%s\" . }}{{ else }}{{ .Content }}{{ end }}\n{{ end }}\n\n{{/* after (Hugo >= 0.141) */}}\n{{ with try (resources.GetRemote $url) }}\n  {{ with .Err }}{{ errorf \"%s\" . }}{{ else with .Value }}{{ .Content }}{{ end }}\n{{ end }}","handlingStrategy":"validation","validationCode":"# find removed Resource.Err usages before upgrading past v0.141.0\ngrep -rn '\\.Err\\b' layouts/ | grep -i resources","typeGuard":null,"tryCatchPattern":"{{/* replace .Err checks with try */}}\n{{ with try (resources.GetRemote $url) }}\n  {{ with .Err }}{{ warnf \"%s\" . }}{{ else }}{{ with .Value }}...{{ end }}{{ end }}\n{{ end }}","preventionTips":["Before upgrading to Hugo ≥ v0.141.0, grep templates for Resource.Err and migrate to the try keyword","Read the release notes for removed template APIs on every minor upgrade","Pin the Hugo version in CI and upgrade deliberately with a template audit"],"tags":["hugo","templates","breaking-change","resources","try"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}