Unmarshal Format Unknown Error

I am using a headless page bundle for my homepage. Inside the bundle there is a JSON file which contains the links to about a dozen videos which play on a videowall on the homepage. The site is in several languages and each language has a separate JSON to provide the correctly translated video links to the video wall partial on the home page.

Most of the time this builds and displays exactly as I expect. However about 1 in 5 time with I build or if hugo rebuilds after detecting a change, I get this error. It’s apparently random and running garbage collection and restarting hugo always fixes the error.

execute of template failed: template: partials/homepage/video-wall.html:33:70: executing “partials/homepage/video-wall.html” at : error calling unmarshal: unknown format

Inside the partial I call

{{ $headless := .Site.GetPage "homepage" }}
{{ $reusablePages := $headless.Resources.GetMatch "videoWall*.json" | unmarshal }}

This is the folder structure for the content.
/ content

I’m not sure why the json’s need to have en and es in them. I tried to using GetMatch videoWall.json and it never found the correct file. It seemingly does not have the context of the headless bundle “homepage”.

Any help would be appreciated. As I said it works perfectly when it works, not sure why that is.

put the JSON in the assetDIr.

In my sample I use it without unmarshal

   {{ $file := .Params.datafile}}{{ $data := getJSON $file }}
    {{ range sort $data.items title}}


datafile = "/assets/links/links.json"

for more help share a (sample) repository

I’m pretty sure only need that if they live in the same content folder, which isn’t your case.

That said, the error you get is odd.

You may get a better error if you rewrite to something like this:

{{ $videoWall := $headless.Resources.GetMatch "videoWall*.json" }}
{{ if not $videoWall }}
{{ errorf "videoWall not found" }}
{{ end }}
{{ $reusablePages := $videoWall | unmarshal }}

It doesn’t solve your problem, but …

Thanks unfortunately that threw the same error. The problem I was having earlier was if I didn’t add the .en.json it would just pull the English version. So if I didn’t differentiate the filename, even within the content folder i.e. /content/en/videoWall.json. It would only ever find the english version.

Edit: After several restarts of hugo and everything working it finally threw the ERROR 2021/06/07 16:17:29 videoWall not found

Edit: I’m going to strip back a sample repo and share it.

I think I may have solved it. I was trying to use named resources in the headless page bundles. When I removed this it seems to have started working correctly. Thanks for the sanity check.