Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE for $parent.File.UniqueID using Hugo 0.123.1. #1874

Closed
2 tasks
Tracked by #1812
chalin opened this issue Feb 25, 2024 · 9 comments · Fixed by #1890
Closed
2 tasks
Tracked by #1812

NPE for $parent.File.UniqueID using Hugo 0.123.1. #1874

chalin opened this issue Feb 25, 2024 · 9 comments · Fixed by #1890
Assignees

Comments

@chalin
Copy link
Collaborator

chalin commented Feb 25, 2024

Originally posted by @chulcher in #1863 (comment)

This appears to be further broken with Hugo 0.123.1.

ERROR render of "taxonomy" failed:
"C:\Users\Carson\AppData\Local\hugo_cache\modules\filecache\modules\pkg\mod\github.com\google\docsy@v0.9.1\layouts\docs\list.html:12:5": execute of template failed: template: docs/list.html:12:5: executing "main" at <partial "section-index.html" .>: error calling partial: "C:\Users\Carson\AppData\Local\hugo_cache\modules\filecache\modules\pkg\mod\github.com\google\docsy@v0.9.1\layouts\partials\section-index.html:8:69": execute of template failed: template: partials/section-index.html:8:69: executing "partials/section-index.html" at <$parent.File.UniqueID>: error calling UniqueID: runtime error: invalid memory address or nil pointer dereference
Built in 936 ms
Error: error building site: render: failed to render pages: render of "taxonomy" failed: "C:\Users\Carson\AppData\Local\hugo_cache\modules\filecache\modules\pkg\mod\github.com\google\docsy@v0.9.1\layouts\docs\list.html:12:5": execute of template failed: template: docs/list.html:12:5: executing "main" – File is nil; wrap it in if or with: {{ with partial "section-index.html" .>: error calling partial: "C:\Users\Carson\AppData\Local\hugo_cache\modules\filecache\modules\pkg\mod\github.com\google\docsy@v0.9.1\layouts\partials\section-index.html:8:69": execute of template failed: template: partials/section-index.html:8:69: executing "partials/section-index.html" at <.File }}{{ .UniqueID }}{{ end }}

gohugoio/hugo#12068, specifically gohugoio/hugo#12068 (comment) relevant?

@chalin
Copy link
Collaborator Author

chalin commented Feb 25, 2024

From #1863 (comment), @chulcher adds:

No idea if this is applying the fix or just hiding the issue but changing:

{{ if and .Parent .Parent.File -}}
        {{ $pages = (where $pages "Parent.File.UniqueID" "==" $parent.File.UniqueID) -}}
{{ end -}}

to:

{{ if and .Parent .Parent.File -}}
    {{with $parent.File}}{{ $pages = (where $pages "Parent.File.UniqueID" "==" .UniqueID) -}}{{end}}
{{ end -}}

allows for a successful build.

@chalin
Copy link
Collaborator Author

chalin commented Feb 25, 2024

Thanks for reporting the issue @chulcher, either @deining or I will look into this as soon as we can. I'm still trying to make my way through the changes introduced by v0.123.

@chalin
Copy link
Collaborator Author

chalin commented Mar 4, 2024

@chulcher @deining - I can't reproduce the error using the instructions I gave in #1866 (comment), so maybe your setup is slightly different?

@chulcher
Copy link

chulcher commented Mar 4, 2024

I only see the error when cascade is configured.

---
type: "docs"
title: "Placeholder"
cascade:
  type: "docs"
---

That's what I've currently configured to get the site to render as only docs. I've verified it with a new, blank site. The build works up until cascade is configurd.

@marshalc
Copy link

marshalc commented Mar 8, 2024

Can confirm this is still there with Hugo 0.123.8 -- I'm just playing catchup since I did an update on local build and started seeing this issue.

tobiaskohlbau added a commit to tobiaskohlbau/docsy that referenced this issue Mar 11, 2024
During rendering the section index of a docs list it could happen
that a file has no parent for e.g. the homepage. If such scenario is
existing the .Parent.File of a file is nil. Therefore this case should
be handled within the rendering itself.

Fixes google#1874

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
@tobiaskohlbau
Copy link
Contributor

tobiaskohlbau commented Mar 11, 2024

I've indentified the root cause. It's caused by for e.g. a homepage to exist, this results in .Parent.File within the $pages list to be empty. The pages containing no file within the parent should be filtered out as well. I've created #1890 to address this.

For anyone curious to test this, add the following to your go.mod file:

replace (
	github.com/google/docsy => github.com/tobiaskohlbau/docsy@v0.0.0-20240311143709-ce2f7c726baa
)

by for eg. executing:

go mod edit --replace=github.com/google/docsy=github.com/tobiaskohlbau/docsy@v0.0.0-20240311143709-ce2f7c726baa

Please let me know if this fixes the issue for you too. On my project it works after applying #1890.

@marshalc
Copy link

I think I'm still having this same problem. Current output from a fairly basic site importing the main docsy (though I get the same error on our ouhft fork):

hugo --cleanDestinationDir --gc --templateMetrics --logLevel debug
hugo: downloading modules …
hugo: collected modules in 25187 ms
Start building sites … 
hugo v0.124.1-db083b05f16c945fec04f745f0ca8640560cf1ec+extended darwin/amd64 BuildDate=2024-03-20T11:40:10Z VendorInfo=brew

INFO  static: removing all files from destination that don't exist in static dirs
INFO  static: syncing static files to / duration 75.860826ms
INFO  build:  step process substep collect files 41 files_total 41 duration 93.319446ms
INFO  build:  step process duration 93.381708ms
INFO  build:  step assemble duration 1.15729ms
INFO  postcss: use config file "/Users/carl/.local/share/hugo/modules/filecache/modules/pkg/mod/github.com/google/docsy@v0.9.2-0.20240315194958-1929a65ccffb/postcss.config.js"
ERROR render of "taxonomy" failed: "/Users/carl/.local/share/hugo/modules/filecache/modules/pkg/mod/github.com/google/docsy@v0.9.2-0.20240315194958-1929a65ccffb/layouts/docs/list.html:12:5": execute of template failed: template: docs/list.html:12:5: executing "main" at <partial "section-index.html" .>: error calling partial: "/Users/carl/.local/share/hugo/modules/filecache/modules/pkg/mod/github.com/google/docsy@v0.9.2-0.20240315194958-1929a65ccffb/layouts/partials/section-index.html:8:69": execute of template failed: template: partials/section-index.html:8:69: executing "partials/section-index.html" at <$parent.File.UniqueID>: error calling UniqueID: runtime error: invalid memory address or nil pointer dereference
INFO  build:  step render pages 40 content 36 duration 2.383305018s
INFO  build:  step postProcess duration 8.41µs

Template Metrics:

     cumulative       average       maximum         
       duration      duration      duration  count  template
     ----------      --------      --------  -----  --------
   36.79086606s  994.347731ms  2.307956508s     37  partials/head.html
  36.500128595s  986.489962ms  2.305459415s     37  partials/head-css.html
    28.1904875s  972.085775ms  2.339776411s     29  docs/single.html
   4.699009226s  783.168204ms  2.342940105s      6  docs/list.html
   2.338307184s  2.338307184s  2.338307184s      1  _default/single.html
   2.318438052s  2.318438052s  2.318438052s      1  404.html
   297.316384ms    8.494753ms   28.370157ms     35  partials/scripts.html
   204.317268ms    5.675479ms    9.083966ms     36  partials/sidebar.html
    180.93288ms    5.025913ms    8.339589ms     36  partials/sidebar-tree.html
   112.305883ms    3.119607ms    7.879768ms     36  partials/page-meta-links.html
    59.438315ms     1.60644ms    4.353763ms     37  partials/navbar.html
    14.499051ms     414.258µs    5.557438ms     35  partials/reading-time.html
     11.34795ms     391.308µs    1.115432ms     29  _default/content.html
    11.028456ms     315.098µs     2.83278ms     35  partials/footer.html
     8.589645ms     117.666µs    1.150916ms     73  partials/search-input.html
     7.063337ms      44.989µs      390.47µs    157  _default/_markup/render-link.html
     6.514924ms      180.97µs    4.386215ms     36  partials/toc.html
     6.402878ms     182.939µs    2.419776ms     35  partials/footer/center.html
     6.105544ms      58.707µs     355.345µs    104  partials/_funcs/get-page-images.html
     5.927825ms     164.661µs     716.317µs     36  partials/taxonomy_terms_clouds.html
     5.540066ms    5.540066ms    5.540066ms      1  shortcodes/blocks/cover.html
     4.743736ms     135.535µs    2.245432ms     35  partials/footer/copyright.html
     4.471639ms     127.761µs     500.316µs     35  partials/taxonomy_terms_article_wrapper.html
     4.381373ms     730.228µs     1.46746ms      6  partials/section-index.html
     4.056066ms    4.056066ms    4.056066ms      1  shortcodes/readfile.html
     3.783642ms     108.104µs      255.44µs     35  partials/hooks/body-end.html
     3.498434ms      94.552µs     457.302µs     37  partials/outputformat.html
       2.4786ms      34.425µs     299.143µs     72  partials/taxonomy_terms_cloud.html
     2.385305ms      34.075µs     272.295µs     70  partials/taxonomy_terms_article.html
      2.24885ms      62.468µs      257.23µs     36  partials/breadcrumb.html
     1.784341ms       25.49µs     126.868µs     70  partials/footer/links.html
     1.757118ms      50.203µs     262.582µs     35  partials/footer/right.html
     1.734223ms      49.549µs      206.14µs     35  partials/footer/left.html
     1.701514ms      51.561µs      256.77µs     33  partials/page-meta-lastmod.html
      1.21014ms       36.67µs      362.02µs     33  partials/feedback.html
      878.166µs      23.734µs     768.382µs     37  partials/favicons.html
      666.468µs     666.468µs     666.468µs      1  _internal/_default/sitemap.xml
      544.647µs      77.806µs     243.606µs      7  _default/_markup/render-image.html
      524.643µs      14.179µs     154.962µs     37  partials/hooks/head-end.html
      332.621µs       9.239µs     124.131µs     36  partials/version-banner.html
      271.238µs      45.206µs     172.369µs      6  shortcodes/alert.html
      194.859µs      64.953µs     175.348µs      3  shortcodes/pageinfo.html
      193.198µs      96.599µs     173.402µs      2  _internal/shortcodes/ref.html
      157.918µs     157.918µs     157.918µs      1  _internal/_default/sitemapindex.xml
        109.4µs      36.466µs      82.859µs      3  shortcodes/blocks/section.html
       88.033µs      88.033µs      88.033µs      1  _internal/_default/robots.txt
       15.243µs      15.243µs      15.243µs      1  /js/search.js
        5.252µs       5.252µs       5.252µs      1  /js/drawio.js
        5.196µs       5.196µs       5.196µs      1  /js/markmap.js
        4.703µs       4.703µs       4.703µs      1  /js/plantuml.js

INFO  build:  duration 2.478542003s
Total in 27935 ms
Error: error building site: render: failed to render pages: render of "taxonomy" failed: "/Users/carl/.local/share/hugo/modules/filecache/modules/pkg/mod/github.com/google/docsy@v0.9.2-0.20240315194958-1929a65ccffb/layouts/docs/list.html:12:5": execute of template failed: template: docs/list.html:12:5: executing "main" – File is nil; wrap it in if or with: {{ with partial "section-index.html" .>: error calling partial: "/Users/carl/.local/share/hugo/modules/filecache/modules/pkg/mod/github.com/google/docsy@v0.9.2-0.20240315194958-1929a65ccffb/layouts/partials/section-index.html:8:69": execute of template failed: template: partials/section-index.html:8:69: executing "partials/section-index.html" at <.File }}{{ .UniqueID }}{{ end }}

I've removed the contents of the Hugo cache (several times) and the same behaviour repeats.

I can see that the edit proposed by @tobiaskohlbau has been included on layouts/partials/section-index.html, i.e.:

    {{ $pages = (where $pages ".Params.hide_summary" "!=" true) -}}
    {{ $pages = (where $pages ".Parent" "!=" nil) -}}
    {{ if and .Parent .Parent.File -}}
        {{ $pages = (where $pages "Parent.File.UniqueID" "==" $parent.File.UniqueID) -}}
    {{ end -}}

I've just been testing this with Hugo 0.124.1, and am presently stumped as to what to try next (apart from trying to revert back to Hugo 0.122.x). Any further suggestions for things I could test please?

@marshalc
Copy link

marshalc commented Mar 20, 2024

I've had a go at reproducing a minimal test site that generates this issue for me - it's at https://github.com/ouhft/docsy-debug-1874 - essentially it confirms what @chulcher pointed out earlier.

I've outlined each step I've taken in the README.md. Short version, the use of the cascade frontmatter element triggers this issue. This hits all my builds since I exclusively use the type: docs template and thus use the cascade directive from the front page of all my sites to save me explicitly putting type: docs in every page output.


Edit 2: I've just tested a larger site with explicitly putting the type:docs in every page where I expect that page type, and that built without errors.

Also, I've tested cascade with type: blog, and that also builds without errors on the test site above.

So, the explicit test seems to be for the use of cascade with type: docs

HTH

@tobiaskohlbau
Copy link
Contributor

Did you use replace statements in order to try my current fork? I've learned that Hugo does not use replace statements with versions only local ones. This means the repository has to be checked out locally and replaced with a relative path.

yann-soubeyrand pushed a commit to camptocamp/docsy that referenced this issue Mar 25, 2024
During rendering the section index of a docs list it could happen
that a file has no parent for e.g. the homepage. If such scenario is
existing the .Parent.File of a file is nil. Therefore this case should
be handled within the rendering itself.

Fixes google#1874

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
yann-soubeyrand pushed a commit to camptocamp/docsy that referenced this issue Mar 25, 2024
During rendering the section index of a docs list it could happen
that a file has no parent for e.g. the homepage. If such scenario is
existing the .Parent.File of a file is nil. Therefore this case should
be handled within the rendering itself.

Fixes google#1874

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
yann-soubeyrand pushed a commit to camptocamp/docsy that referenced this issue Mar 26, 2024
During rendering the section index of a docs list it could happen
that a file has no parent for e.g. the homepage. If such scenario is
existing the .Parent.File of a file is nil. Therefore this case should
be handled within the rendering itself.

Fixes google#1874

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
yann-soubeyrand pushed a commit to camptocamp/docsy that referenced this issue Mar 26, 2024
During rendering the section index of a docs list it could happen
that a file has no parent for e.g. the homepage. If such scenario is
existing the .Parent.File of a file is nil. Therefore this case should
be handled within the rendering itself.

Fixes google#1874

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
chalin pushed a commit to tobiaskohlbau/docsy that referenced this issue Mar 26, 2024
During rendering the section index of a docs list it could happen
that a file has no parent for e.g. the homepage. If such scenario is
existing the .Parent.File of a file is nil. Therefore this case should
be handled within the rendering itself.

Fixes google#1874

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
yann-soubeyrand pushed a commit to camptocamp/docsy that referenced this issue Mar 29, 2024
During rendering the section index of a docs list it could happen
that a file has no parent for e.g. the homepage. If such scenario is
existing the .Parent.File of a file is nil. Therefore this case should
be handled within the rendering itself.

Fixes google#1874

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
yann-soubeyrand pushed a commit to camptocamp/docsy that referenced this issue Apr 2, 2024
During rendering the section index of a docs list it could happen
that a file has no parent for e.g. the homepage. If such scenario is
existing the .Parent.File of a file is nil. Therefore this case should
be handled within the rendering itself.

Fixes google#1874

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
yann-soubeyrand pushed a commit to camptocamp/docsy that referenced this issue Apr 2, 2024
During rendering the section index of a docs list it could happen
that a file has no parent for e.g. the homepage. If such scenario is
existing the .Parent.File of a file is nil. Therefore this case should
be handled within the rendering itself.

Fixes google#1874

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
yann-soubeyrand pushed a commit to camptocamp/docsy that referenced this issue Apr 2, 2024
During rendering the section index of a docs list it could happen
that a file has no parent for e.g. the homepage. If such scenario is
existing the .Parent.File of a file is nil. Therefore this case should
be handled within the rendering itself.

Fixes google#1874

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
chalin pushed a commit to tobiaskohlbau/docsy that referenced this issue Apr 7, 2024
During rendering the section index of a docs list it could happen
that a file has no parent for e.g. the homepage. If such scenario is
existing the .Parent.File of a file is nil. Therefore this case should
be handled within the rendering itself.

Fixes google#1874

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
yann-soubeyrand pushed a commit to camptocamp/docsy that referenced this issue Apr 8, 2024
During rendering the section index of a docs list it could happen
that a file has no parent for e.g. the homepage. If such scenario is
existing the .Parent.File of a file is nil. Therefore this case should
be handled within the rendering itself.

Fixes google#1874

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
@chalin chalin mentioned this issue Apr 8, 2024
21 tasks
chalin pushed a commit to tobiaskohlbau/docsy that referenced this issue Apr 8, 2024
During rendering the section index of a docs list it could happen
that a file has no parent for e.g. the homepage. If such scenario is
existing the .Parent.File of a file is nil. Therefore this case should
be handled within the rendering itself.

Fixes google#1874

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
yann-soubeyrand pushed a commit to camptocamp/docsy that referenced this issue Apr 12, 2024
During rendering the section index of a docs list it could happen
that a file has no parent for e.g. the homepage. If such scenario is
existing the .Parent.File of a file is nil. Therefore this case should
be handled within the rendering itself.

Fixes google#1874

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
chalin pushed a commit to tobiaskohlbau/docsy that referenced this issue Apr 23, 2024
During rendering the section index of a docs list it could happen
that a file has no parent for e.g. the homepage. If such scenario is
existing the .Parent.File of a file is nil. Therefore this case should
be handled within the rendering itself.

Fixes google#1874

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
chalin pushed a commit to tobiaskohlbau/docsy that referenced this issue Apr 25, 2024
During rendering the section index of a docs list it could happen
that a file has no parent for e.g. the homepage. If such scenario is
existing the .Parent.File of a file is nil. Therefore this case should
be handled within the rendering itself.

Fixes google#1874

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants