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