Netlify deployment only: nil pointer evaluating resource.Resource.Permalink

Hi all,
Wonder if you can help me.
Trying to publish new site into Netlify from Github and facing below error

10:22:06 PM: hugo v0.88.1-5BC54738+extended linux/amd64 BuildDate=2021-09-04T09:39:19Z VendorInfo=gohugoio
10:22:07 PM: Error: Error building site: "/opt/build/repo/layouts/_default/_markup/render-image.html:43:20": execute of template failed: template: _default/_markup/render-image.html:43:20: executing "_default/_markup/render-image.html" at <$image.Permalink>: nil pointer evaluating resource.Resource.Permalink

Where I know what that issue is, the problem is, that there is no failure in any local builds. Tried serving hugo and just publishing (creating public folder) in two different operating systems (macOS and Windows) and none of them reported any problems but when trying to publish to netlify suddenly I got the issue above.

In case you ask render-image.html*

{{- $image := resources.Get .Destination -}}

{{ if .Title }}
  <picture role="img" aria-labelledby="figcaption">
    {{ $isJPG := eq (path.Ext .Destination) ".jpg" }}
    {{ $isPNG := eq (path.Ext .Destination) ".png" }}

    {{ if ($isJPG) -}}
      {{ $webp:= resources.Get (replace .Destination ".jpg" ".webp") }}
        <source srcset="{{ $webp.Permalink | safeURL }}" type="image/webp" >
    {{- end }}

    {{ if ($isPNG) -}}
      {{ $webp:= resources.Get (replace .Destination ".png" ".webp") }}
        <source srcset="{{ $webp.Permalink | safeURL }}" type="image/webp" >
    {{- end }}

    <img
      src="{{ $image.Permalink | safeURL }}"
      sizes="100vw"
      alt="{{ .Text }}"
      loading="lazy"
      decoding="async"
    />
    <span id="figcaption">{{ .Title }}</span>
  </picture>
{{ else }}
  <picture>
    {{ $isJPG := eq (path.Ext .Destination) ".jpg" }}
    {{ $isPNG := eq (path.Ext .Destination) ".png" }}

    {{ if ($isJPG) -}}
      {{ $webp:= resources.Get (replace .Destination ".jpg" ".webp") }}
        <source srcset="{{ $webp.Permalink | safeURL }}" type="image/webp" >
    {{- end }}

    {{ if ($isPNG) -}}
      {{ $webp:= resources.Get (replace .Destination ".png" ".webp") }}
        <source srcset="{{ $webp.Permalink | safeURL }}" type="image/webp" >
    {{- end }}

    <img
      src="{{ $image.Permalink | safeURL }}"
      sizes="100vw"
      alt="{{ .Text }}"
      loading="lazy"
      decoding="async"
    />
  </picture>
{{ end }}

I even removed repository and pushed it under different and repeated deployment with same result.

In config I got set assetDir = "content"

Are you using Hugo Modules to pull the images from another repository?

No, everything in single repo

Can you share it? Privately if you wish.

The default Hugo version on Netlify is below the one that introduced image processing which is the most common reason that happens. If you have a netlify.toml please post here, if not, read the documentation and set appropriate version numbers:

Added you to repo on github so you can pull it on your end.

My theory is

  • one of the filename in netlify environment contain illegal character
  • filename is too long for netlify environment?

As it failing in images, I am thinking on this specific example:

[![HR Assembly – Figure 7 b) & 8 a)](/images/2015/12/figure-7-b-8-a.png "HR Assembly – Figure 7 b) & 8 a)")](/images/2015/12/figure-7-b-8-a.png)

Title of the image contain ) symbol that may be interpreted incorrectly in Netlify Environment? but working fine in any local?

Will investigate possible missing backslash escape character

You have a file name problem. My system is case-sensitive.

diff --git a/content/ce-ukca.md b/content/ce-ukca.md
index f67a721..7c74cf5 100644
--- a/content/ce-ukca.md
+++ b/content/ce-ukca.md
@@ -12,7 +12,7 @@ tags: ['andrews fasteners', 'Assemblies', 'Bolt', 'bolts', 'CE', 'ce approved',
 
 ### CE Mark
 
-![CE Logo](/svg/ce-logo.svg)
+![CE Logo](/svg/CE-logo.svg)
 {.p20right}

Also, you need to fix your render hook to throw an error when it fails, telling you where it failed and what it failed on.

1 Like

Superb, highly appreciate.

Really surprised that in macOS and Windows it didn’t thrown an error. Will work on that.

Just wondering do you have such an example, an image render hook template that prints a console error message specifying the page in which the error happened?

We’ve all been beaten by this error.
Typically when this happens I revert changes incrementally until I find the culprit.
Sometimes it’s not obvious at all and it does take time.
A more specific console message would help.

2 Likes

For the record, I have tried to use custom error handling in an image render hook template:

{{- $image := .Page.Resources.GetMatch (printf "%s" (.Destination | safeURL)) -}}
<img src="{{ with $image.Permalink }}{{ . }}{{ else }}{{ errorf "Failed to find image in page %q" .Path }}{{ end }}"/>

However whenever an image cannot be found, I am still getting the generic and unhelpful error:

Error: Error building site: "/../layouts/_default/_markup/render-image.html:4:100": execute of template failed: template: _default/_markup/render-image.html:4:100: executing "_default/_markup/render-image.html" at <$image.Permalink>: nil pointer evaluating resource.Resource.Permalink
{{ with .Page.Resources.GetMatch .Destination }}
  <img src="{{ .RelPermalink }}" alt="{{ $.Text }}" width="{{ .Width }}" height="{{ .Height }}">
{{ else }}
  {{ errorf "Unable to locate %q for placement on %q" .Destination .Page.Path }}
{{ end }}

ERROR 2021/11/12 04:38:54 Unable to locate “c.jpg” for placement on “cats/cat-3/index.md”

2 Likes

Interesting. So the entire markup needs to be placed within the condition for the custom errorf to be evaluated, also the use of .Destination .Page.Path is noted.

Hadn’t thought of writing the condition like this. Thank you very much @jmooring

Also I think that your example needs to be included in the docs as Custom Error Handling for Markdown Render Hooks (or similar), because debugging without your technique is needlessly time consuming.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.