Hugo: Nil pointer evaluating resource.Resource.Resize since version 0.57.0

Created on 21 Oct 2019  Â·  1Comment  Â·  Source: gohugoio/hugo

Hello,
For a better follow-up of my problem that I opened on the forum https://discourse.gohugo.io/t/nil-pointer-evaluating-resource-resource-resize-in-version-0-57-0/20208 I allow myself to open a ticket


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 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

pkollitsch write:

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 2), 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?

Bep write :

This sounds like a bug: https://github.com/gohugoio/hugo/issues/6210

Jee write :

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 )

Bep write

@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 …

Speeder write

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 }}

aidan write

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!

What version of Hugo are you using (hugo version)?

Hugo Static Site Generator v0.59.0-1DD0C69C/extended linux/amd64 BuildDate: 2019-10-21T09:45:38Z

Does this issue reproduce with the latest release?

Yes it bug since 0.57.0
I'm staying on the version 0.56.3 for now.
Hugo Static Site Generator v0.56.3-F637A1EA/extended linux/amd64 BuildDate: 2019-07-31T12:54:46Z

>All comments

GetMatch returns nil if not found, so you need to check with if or with. Take further questions on the forum. If you still believe this is a bug, please open a new issue with a reference to a failing site. I'm not sure what you'd expect us to do with all the text above.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

moorereason picture moorereason  Â·  3Comments

MunifTanjim picture MunifTanjim  Â·  3Comments

ianbrandt picture ianbrandt  Â·  3Comments

nikolas picture nikolas  Â·  3Comments

bep picture bep  Â·  3Comments