Some users reported an error when building my theme on Windows using the exampleSite. The error doesn’t happen on Linux or Mac. I added a Windows runner to repro the error, which looks like this:
WARN 2023/02/19 20:32:55 @@@@@@@@@@@@@@@ GetMatch "paige/bootstrap-icons/bootstrap-icons.css"
WARN 2023/02/19 20:32:55 @@@@@@@@@@@@@@@ GetMatch "paige/bootstrap/bootstrap.css"
WARN 2023/02/19 20:32:55 @@@@@@@@@@@@@@@ GetMatch "paige/bootstrap/bootstrap.bundle.js"
WARN 2023/02/19 20:32:55 @@@@@@@@@@@@@@@ GetMatch "paige/katex/katex.css"
WARN 2023/02/19 20:32:55 @@@@@@@@@@@@@@@ GetMatch "paige/katex/katex.js"
WARN 2023/02/19 20:32:55 @@@@@@@@@@@@@@@ GetMatch "paige/katex/auto-render.js"
WARN 2023/02/19 20:32:55 @@@@@@@@@@@@@@@ GetMatch "https://picsum.photos/400/300.webp"
WARN 2023/02/19 20:32:55 @@@@@@@@@@@@@@@ GetMatch "landscape.webp"
Error: Error building site: "D:\a\paige\paige\exampleSite\content\shortcodes\gallery\index.md:27:1": failed to render shortcode "paige/gallery": failed to process shortcode: execute of template failed: template: shortcodes/paige/gallery.html:22:23: executing "shortcodes/paige/gallery.html" at <partial "paige/func-resource.html" (dict "page" .Page "url" $image)>: error calling partial: "D:\a\paige\paige\layouts\partials\paige\func-resource.html:15:25": execute of template failed: template: partials/paige/func-resource.html:15:25: executing "partials/paige/func-resource.html" at <resources.GetMatch>: error calling GetMatch: runtime error: invalid memory address or nil pointer dereference
Here’s that error split into lines:
Error:
Error building site: "D:\a\paige\paige\exampleSite\content\shortcodes\gallery\index.md:27:1":
failed to render shortcode "paige/gallery":
failed to process shortcode:
execute of template failed:
template: shortcodes/paige/gallery.html:22:23:
executing "shortcodes/paige/gallery.html" at <partial "paige/func-resource.html" (dict "page" .Page "url" $image)>:
error calling partial: "D:\a\paige\paige\layouts\partials\paige\func-resource.html:15:25":
execute of template failed:
template: partials/paige/func-resource.html:15:25:
executing "partials/paige/func-resource.html" at <resources.GetMatch>:
error calling GetMatch:
runtime error: invalid memory address or nil pointer dereference
To clarify that a bit, paige\exampleSite\content\shortcodes\gallery\index.md:27:1
is the first line of this:
{{< paige/gallery >}}
{{< paige/gallery image="https://picsum.photos/400/300.webp" />}}
{{< /paige/gallery >}}
I assume the actual line in question is the second line containing https://picsum.photos/400/300.webp
. (This seems like a bug in line reporting.)
shortcodes/paige/gallery.html:22:23
is the first line of
{{ $resource = partial "paige/func-resource.html" (dict
"page" .Page
"url" $image
) }}
paige\layouts\partials\paige\func-resource.html:15:25
is the second line of
{{ warnf "@@@@@@@@@@@@@@@ GetMatch %#v" $url }}
{{ with resources.GetMatch $url }}
As you saw in the raw output at the top, the value of $url
was (probably) https://picsum.photos/400/300.webp
(the last value printed was technically landscape.webp
, but the picsum URL matches the outermost context; perhaps the landscape string was from parallel work?).
The exact source is at GitHub - willfaught/paige at a62912535e57532a5da5d4743ae2d743e81a245b.
So, it seems to me that resources.GetMatch("https://picsum.photos/400/300.webp")
works on Linux and Mac (returning nil), but not on Windows (panics instead of returning nil), unless I’m missing something. Certainly, a panic shouldn’t be happening at all. I’m not sure how to debug this any further, since I don’t have access to a Windows computer right now.
I tried checking for remote resources first, so that a URL is never given to GetMatch, but it still results in a panic:
Error: Error building site: "D:\a\paige\paige\exampleSite\content\shortcodes\gallery\index.md:27:1": failed to render shortcode "paige/gallery": failed to process shortcode: execute of template failed: template: shortcodes/paige/gallery.html:49:23: executing "shortcodes/paige/gallery.html" at <partial "paige/img.html" (dict "class" "img-fluid" "height" $height "maxheight" $maxheight "maxwidth" $maxwidth "method" $method "options" $options "resource" $resource "src" $image "width" $width)>: error calling partial: "D:\a\paige\paige\layouts\partials\paige\img.html:50:35": execute of template failed: template: partials/paige/img.html:50:35: executing "partials/paige/img.html" at <$resource.Height>: error calling Height: runtime error: invalid memory address or nil pointer dereference
This time, it makes it a bit further down gallery.html
to shortcodes/paige/gallery.html:49:23
, which is the first line of:
"content" (partial "paige/img.html" (dict
"class" "img-fluid"
"height" $height
"maxheight" $maxheight
"maxwidth" $maxwidth
"method" $method
"options" $options
"resource" $resource
"src" $image
"width" $width
))
paige\layouts\partials\paige\img.html:50:35
is
{{ $intrinsicheight = $resource.Height }}
Here, $resource is passed in as a param from gallery.html, where it was gotten from the paige/func-resource.html
partial that was causing the first problem above. So, by avoiding passing the URL to GetMatch, we seem to have just kicked the can down the road a little. The remote resource is still causing a panic, this time when trying to use its height.
The exact source for the remote resource workaround is at GitHub - willfaught/paige at e6b4ae431937d9ed075d057f4694b143b623ac47.
Any help is much appreciated!
Edit 1: Hugo 0.102.3 is used in the Windows GitHub runner.
Edit 2: Cleaned up copied log output.
Edit 3: Note that --verbose --verboseLog --log
unfortunately didn’t add any extra output for debugging.
Edit 4: Updated commit for new windows branch.
Edit 5: Add remote resource workaround commit link.