"error calling Data: term is empty" when using Content Adapter to populate tags

Previously:

Reproducible build available at GitHub - trwnh/hugo-bug-reproducibles at term-is-empty

term-is-empty

hugo v0.138.0+extended linux/amd64 BuildDate=unknown

data/tags/yugioh.json

{
	"@context": [
		"https://www.w3.org/ns/activitystreams",
		{
			"@base": "https://trwnh.com/tags/"
		}
	],
	"id": "yu-gi-oh!",
	"name": "Yu-Gi-Oh!",
	"summary": "A media franchise including several series mostly revolving around the fictional card game of Duel Monsters.",
	"alsoKnownAs": ["yu-gi-oh", "ygo", "yugioh"]
}

content/tags/_content.gotmpl

{{ $data := .Site.Data.tags }}
{{ $ctx := . }}


{{ range $data }}

	{{ $id := .id }}
	{{ $title := .name }}
	{{ $summary := .summary }}
	{{ $aliases := .alsoKnownAs }}

	{{ $page := dict
		"title" $title
		"summary" $summary
		"params" (dict "tag_aliases" $aliases "tag_name" $id)
		"path" .id
		"url" (printf "tags/%s" .id)
		"kind" "term"
	}}
	{{ $.AddPage $page }}

	{{ range $aliases }}
		{{ $page := dict
		"params" (dict "tag_canonical" $id "tag_name" .)
		"path" .
		"url" (printf "tags/%s" .)
		"kind" "term"
		}}
		{{ $.AddPage $page }}
	{{ end }}

{{ end }}

layouts/_default/taxonomy.html

{{ define "body" }}
{{/*  this fails with "error calling Data: term is empty"  */}}
<dl>
{{ range .Data.Terms.ByCount }}
	<dt>{{.Name}} -- <a href="{{.Permalink}}">{{.Permalink}}</a></dt>
	<dd>used {{.Count}} time(s)</dd>
{{ end }}
</dl>
{{ end }}

I assume that this is because there are no pages in content/ that include at least one of the terms for which I called .AddPage via a Content Adapter. So for example, if I am defining term aliases such that yu-gi-oh! is canonical and ["yu-gi-oh", "ygo", "yugioh"] are aliases, and I am calling .AddPage a total of 4 times due to this, then the entire build/server fails because Hugo is expecting at least 1 page to be included in each of those 4 terms.

Both .Data and .Site.Taxonomies cause this “term is empty” error.

The former is especially problematic because I want to loop over .Data.Terms.ByCount to sort my tags list on the taxonomy page by most used tags. I am feeling like the answer here might end up being “use Scratch/Store to range over all .Site.Pages/RegularPages and reimplement the counter/total yourself”, but I am posting this thread just in case there’s an easier option I’m overlooking…

This looks like a bug …

1 Like

That said … I cannot reproduce it. Your test repo does not fail for me. Also, I remember having fixed this issue some time ago. Are you sure you have tested with a reasonably new Hugo version?

Oh, I pushed a change which commented the problematic code out; let me push the broken version again.

EDIT: pushed to GitHub - trwnh/hugo-bug-reproducibles at term-is-empty again.

EDIT 2: I am using Hugo v0.138.0 and also tested with 0.137.1 before I updated to 138

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