Nil pointer evaluating resource.Resource.Resize in version 0.57.0

Hello, it’s look like something is broken my template don’t work anymore in 0.57 but it work in 0.56.*
i get this error

Error: Error building site: failed to render pages: render of "home" failed: execute of template failed: template: index.html:13:4: executing "index.html" at <partial "photo/entry.html" .>: error calling partial: "/var/www/": execute of template failed: template: partials/photo/entry.html:22:28: executing "partials/photo/entry.html" at <$images.Resize>: nil pointer evaluating resource.Resource.Resize

the part of partials/photo/entry.html who cause troubles :

{{ if .Params.cover }}
  {{ $images := .Resources.GetMatch .Params.cover }}
  {{ $cover := $images.Resize "600x q95 lancoz" }}
  <a href="{{ .Permalink }}"><img class="u-photo" src="{{ $cover.RelPermalink }}" width="80%" height="auto"></a>
{{ else }}
  {{ $images := .Resources.GetMatch "pix/*" }}
  {{ $cover := $images.Resize "600x q95 lancoz" }}
  <a href="{{ .Permalink }}"><img class="u-photo" src="{{ $cover.RelPermalink }}" width="80%" height="auto"></a>
{{ end }}

Did I miss something? Thank you

Yep there is a whole chapter in the release notes that something changed with resources and matches:

Resources Loading from Assets with Wildcards : We have added two new sought after template functions to the resources namespace: resources.Match and resources.GetMatch . These behaves like their namesake methods on Page (with super-asterisk wildcard support), but searches in all the resources in Assets. E.g. {{ $prettyImages := resources.Match "images/**pretty.jpg" }} will give a slice of all “pretty pictures”. Another relevant example: {{ $js := resources.Match "libs/*.js" | resources.Concat "js/bundle.js" }} .

This is probably connected.

Basically resource.Resource. at the end of the error message sounds suspicious. What line exactly is line 22 in entry.html?

This sounds like a bug:

Hi thank you for your answer.
I read this part in the release note but to be honest I didn’t understand everything I’m not a dev and English is not my native language, sorry for that i try to do my best.

the line 22 is the second :

{{ $cover := $images.Resize "600x q95 lancoz" }}

i guess this line is in error because the line before can’t get an image ( nil )

If this worked in 0.56 it is a bug, but I have some troubles understanding how/what. I have plenty of working similar tests/sites. Is your site source available to test on GitHub or something?

Code source of my site is not public for now, but i have make a tar.gz with the minimal required to test. I send you the link to download it in private :slight_smile:

@Jee OK, I now understand. The template functions in resources.* e.g. resources.GetMatch only looks in the combined /assets folder for images.And when not found it returns nil …

1 Like

Just bumped into this bug or similar one In my case I am more sure is a bug, I made the site on another computer that has Hugo 0.53, then when attempting to load it on hugo 0.57.2 I got this:

“nil pointer evaluating resource.Resource.RelPermalink”

The code with error

{{ range .Pages }}
    <div class="retangulo-redondo">
    <a href="{{.RelPermalink}}">
    <img src="{{ ((.Resources).GetMatch "thumb*").RelPermalink }}" class="imagem-pequena">
{{ end }}

Is there anything new about this bug ? a fix or a workaround ?

1 Like

I am also running into this issue in 0.58. Has there been a recommendation for a fix?

The output from hugo env is:

Hugo Static Site Generator v0.58.3/extended darwin/amd64 BuildDate: unknown GOOS="darwin" GOARCH="amd64" GOVERSION="go1.13"


I have open a ticket on github for a better follow-up of this issue and I hope for a solution :slight_smile: