Strange error message

My static blogs on my host are working fine.
But, I wanted to do some local tests before making some changes.

The message below is strange because it claims I am using Page.URL in the layout partials/post-list.html. But, when I do a search across the entire content directories the string Page.URL never appears in any file anywhere in the site content for this blog. So, what could be triggering this message? Also, Page.Hugo doesn’t exist. It’s like Hugo is looking at some completely different site definition.

Where is Hugo finding Page.URL:

 hugo -d ~/Dropbox/site-output/test
Building sites … WARN 2020/06/17 11:30:42 Page.URL is deprecated and will be removed in a future release. Use .Permalink or .RelPermalink. If what you want is the front matter URL value, use .Params.url
WARN 2020/06/17 11:30:42 Page.Hugo is deprecated and will be removed in a future release. Use the global hugo function.
Total in 696 ms
Error: Error building site: failed to render pages: render of "home" failed: execute of template failed: template: index.html:10:9: executing "index.html" at <partial "post-list" .>: error calling partial: "/Users/lewis/Dropbox/site-content/test/layouts/partials/post-list.html:34:24": execute of template failed: template: partials/post-list.html:34:24: executing "partials/post-list.html" at <index .Site.Data.authors>: error calling index: value is nil; should be of type string

The Page.URL message is only WARN message (not breaking the build).

The Page.Hugo is called via .Hugo variable.

The ERROR tiggered by this.

execute of template failed: template: partials/post-list.html:34:24: executing “partials/post-list.html” at
<index .Site.Data.authors>: error calling index: value is nil; should be of type string

Despite the error, the site built locally (as a test).

It has always built on my host—but I don’t see those messages: I would only notice failure, which hasn’t happened.

It is probably not able to find the param “author” on one or more page(s).
So, the value returned is nil for on that page/pages. Since index needs non nil values for both of its arguments, it is throwing the error

Check how the partial post-list.html is trying to loop over the pages to understand which set of pages you are looping through. Then check all the pages for the param “author”.

Make sure this param is present in all of the pages you are looping through in the partial.

1 Like

Thanks. So easy to fix.

I really don’t understand the Go template language so this is the offending part of the post-list.html layout:

{{ $author := index .Site.Data.authors }}

<span class="post-card-author"><a href="{{ (print "author/" (lower $ | absURL}}">{{$ | default}}</a></span>

Looks like the footer on the post-list page needs to find either $ or $ is set above. I am assuming this comes from the default author from config.toml and the other is Is the second read from the params of each page? All of my post pages have author=””. Could this error come from the template of the page generated for the posts by author page?

I should also have pointed out that the error doesn’t seem to prevent the site from being generated:

Sorry for gyrating on this.

The footer in the layout is the footer of the postcard and all it contains is the author’s name and little icon. All of the postcards display both name and icon.

So, it seems like the error message is spurious or refers to some other layout?

I looked through all of the posts and none are missing the author from the post params top matter.

Final for a while until some answers are clearer.

So, the message says that the error occurs generating the “home” page. I assume this means the top level index.html page.

Well, it is generated. The post-cards all have footers containing name of the author of the corresponding page.

I can’t see anything obviously wrong on any of the pages.

Take a look-see if you want:


The problem is now obvious with the 2 lines of code that you posted.

The first line tries to fetch the information of the author from the file /data/author.toml.
The second line gives you the liberty that if the author name is not present in the author.toml, then it would default to the Site’s default author (provided by config.toml)

The above lines of code does not handle the situation of null index.

Since you stated that all of your pages have author set to “”, this is what’s causing the error.

As a remedy you could set the author explicitly in all your pages in the front matter (painful!!!), or replace the two lines of code that you posted with the below code:

{{ $mainauthor := }}
{{ $allauthors := .Site.Data.authors }}

{{ with }}
    {{ $author := index $allauthors . }}
    <span class="post-card-author"><a href="{{ (print "author/" (lower $ | absURL}}">{{$ | default $mainauthor}}</a></span>
{{ else }}
    <span class="post-card-author"><a href="{{ (print "author/" (lower $mainauthor)) | absURL}}">{{ $mainauthor }}</a></span>
{{ end }}

Please note that I did not test this code, so it may have typos. I would request you to test them in your local first.

This is great. I’ll give it a shot. I was about to give up because there are so many problems with casper3.

My god. two hours of lost time to figuring this out. Thank you so much.