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/jeer.fr/themes/cactus/layouts/partials/photo/entry.html:22:28": 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

1 Like

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: https://github.com/gohugoio/hugo/issues/6210

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">
    <br>{{.Title}}</a>
    </div>
{{ end }}

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

2 Likes

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"

Thanks!

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

3 Likes

I am using Hugo Static Site Generator v0.68.3/extended linux/amd64 and I have the same problem.

ERROR 2020/09/06 10:01:58 render of "home" failed: execute of template failed: template: index.html:4:7: executing "main" at <partialCached "sidebar/left.html" .>: error calling partialCached: "/home/linhk/文档/oi.lhkstudio.me/themes/stack/layouts/partials/sidebar/left.html:12:44": execute of template failed: template: partials/sidebar/left.html:12:44: executing "partials/sidebar/left.html" at <$avatar.Resize>: nil pointer evaluating resource.Resource.Resize
Built in 31 ms
Error: Error building site: failed to render pages: render of "page" failed: execute of template failed: template: _default/single.html:4:7: executing "main" at <partial "sidebar/left.html" .>: error calling partial: "/home/linhk/文档/oi.lhkstudio.me/themes/stack/layouts/partials/sidebar/left.html:12:44": execute of template failed: template: partials/sidebar/left.html:12:44: executing "partials/sidebar/left.html" at <$avatar.Resize>: nil pointer evaluating resource.Resource.Resize

Hi there @Linhk1606,

This topic is almost a year old and several versions behind the current 0.74.3: https://github.com/gohugoio/hugo/releases

Please have a read about Requesting Help to see how to ask for help.

Once you have done so please open a new topic describing your issue.

1 Like