hextra icon indicating copy to clipboard operation
hextra copied to clipboard

Nil pointer dereference in /json/search-data.json with .File.BaseFileName after upgrading to v0.8.5

Open nakednous opened this issue 1 year ago • 5 comments

Description

After upgrading from Hextra v0.8.4 to v0.8.5, the site build fails due to an error in /json/search-data.json. The .File.BaseFileName property references a nil value, leading to a runtime error. The issue occurs on a multilingual site with English and a partial Spanish translation.

Steps To Reproduce

  1. Upgrade Hextra to v0.8.5.
  2. Run hugo server --buildDrafts --disableFastRender.
  3. Observe the error in the console.

Expected Behavior

The site should build successfully without errors.

Actual Behavior

The build fails with a nil pointer dereference error.

Screenshots

N/A

Environment

  • Hugo Version: v0.136.0
  • Browser/OS: Firefox, Arch Linux
  • Theme Version: v0.8.5

Additional Context

The log error is:

Error: error building site: EXECUTE-AS-TEMPLATE: failed to transform "/json/search-data.json" (application/json): template: /json/search-data.json:14:51: executing "/json/search-data.json" at <$page.File.BaseFileName>: error calling BaseFileName: runtime error: invalid memory address or nil pointer dereference

nakednous avatar Oct 17 '24 16:10 nakednous

Hi, thanks for reporting. Do you have the link to the site source or a minimal reproducible example?

imfing avatar Oct 17 '24 17:10 imfing

Caused by this https://github.com/imfing/hextra/commit/a97a1791cc518d9d78d7fc54deead77d65877895#diff-878d857f7dcdc7fd275c8ebd8d44c3894aee03519344b2cc1b55c079314a4bfeL10

The error is caused by a page that doesn't have a file, previously excluded because it didn't have Content either.

It could be fixed if pages without a File are excluded (??), but I'm also curious to see en example.

Gr3q avatar Oct 18 '24 20:10 Gr3q

Caused by this a97a179#diff-878d857f7dcdc7fd275c8ebd8d44c3894aee03519344b2cc1b55c079314a4bfeL10

The error is caused by a page that doesn't have a file, previously excluded because it didn't have Content either.

It could be fixed if pages without a File are excluded (??), but I'm also curious to see en example.

Right, that exclusion line is the only change we made. Not sure why page.File.BaseFileName would cause a nil pointer dereference panic, maybe could also be a Hugo bug?

imfing avatar Oct 19 '24 09:10 imfing

@Gr3q i'll revert the search-data line change for now as I saw another person ran into the same issue

imfing avatar Oct 21 '24 15:10 imfing

@Gr3q i'll revert the search-data line change for now as I saw another person ran into the same issue

done, cut a new release that reverts the change in search-data.json: https://github.com/imfing/hextra/releases/tag/v0.8.6

will look into the root cause when I have time.

imfing avatar Oct 21 '24 21:10 imfing