0.92: New warning when section has no index

@bep I think I found a bug…

Even though I have no references to .File.Path or .Path in my layouts I am getting:

Start building sites … 
hugo v0.92.0-B3549403+extended linux/amd64 BuildDate=2022-01-12T08:23:18Z VendorInfo=gohugoio
WARN 2022/01/15 08:26:09 .File.Path on zero object. Wrap it in if or with: {{ with .File }}{{ .Path }}{{ end }}

I was unable to use --panicOnWarning due to Check hang on --panicOnWarning · Issue #9380 · gohugoio/hugo · GitHub, however I was able to narrow the issue down to having a section (/content/post) with no index. (Neither _index.md nor index.md, nor index.html, etc).

I have created a small test case in the following repo:

Is this a case of this was always an error but wasn’t caught before, or is it a bug?

By just scanning your example repo, I was unable to figure out why you get that error.

But it’s ok to not have index or _index for a section. The list.html layout (I saw that you have that) will take care of rendering the post section for you.

I had created this example repo yesterday and it generates the site alright even without index.md or _index.md.

@kaushalmodi I appreciate your thoughts, but apparently my description wasn’t clear enough: This WARN (non-fatal, the site still builds) is new and does not occur with older versions of Hugo. It’s not a build-breaker, just a warning, but it’s still not right, hence the post.

If you put an index.md or _index.md in the /content/post directory the WARN is no longer emitted. It’s also not a result of use of .File.Path, and therefore whatever the issue is, the error message is incorrect.

I am using latest release as of today (0.92.0). See footer of Hello | Hugo MWE

Also, I don’t recall seeing a warning when I was building it locally.

It could be related my repo being a Hugo module and yours not. I tested your repo in my environment it does not exhibit the issue, however your repo is also not a Hugo module and does not use Hugo modules.

TLDR: Invoking .Page.RenderString on a page without a backing file throws an erroneous warning.

This may be related to:

Really simple example…

git clone --single-branch -b hugo-forum-topic-36590 https://github.com/jmooring/hugo-testing hugo-forum-topic-36590
cd hugo-forum-topic-36590

You will see this warning:

WARN .File.Path on zero object. Wrap it in if or with: {{ with .File }}{{ .Path }}{{ end }}

To remove the warning either:

  1. hugo new content/post/_index.md, or
  2. Remove the call to .RenderString from layouts/_default/list.html

Will you add a comment to https://github.com/gohugoio/hugo/issues/9383?

Already on it! :grinning_face_with_smiling_eyes:

@jmooring I kept it pretty brief, and mentioned this topic. Would you like me to add more details to the GitHub issue itself?

1 Like

No, but please keep an eye on the issue. The two things kind of smell the same, but may be separate issues.

1 Like

FYI, I took a slightly more complex approach and added

{{ if .File }}
  code using .RenderString as before
{{ else }}
  code with markdownify instead of .RenderString
{{ end }}

It seems to work.

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

Now tracking here:

1 Like

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