Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Confusing error when frontmatter contains unknown key/Panic when hugo server reloads on fix #14886

@mavolin

Description

@mavolin

If the frontmatter contains an unrecognized key , hugo build fails with a rather unhelpful error message:

---
params:
featuredImage: featured.png # forgot to indent
---
€ hugo build -D
Start building sites …
hugo v0.161.1+extended+withdeploy linux/amd64 BuildDate=unknown VendorInfo=nixpkgs

Total in 33 ms
ERROR error building site: assemble: failed to create page from pageMetaSource /news: "[redacted]/website/content/news/_index.md:1:1": unable to cast <nil> of type <nil> to map[string]interface {}

When running hugo server and fixing the error, the server panics:

To reproduce:

  1. Correctly indent featuredImage.
  2. Start hugo server
  3. Unindent featuredImage, and save
  4. Get the error above
  5. Reindent, fixing the error, and save
  6. Server panics, while calling hugo server again works as expected
€ hugo server -D
# ...

# 1.
Built in 105 ms
Environment: "development"
Serving pages from disk
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1) 
Press Ctrl+C to stop

# 3.
Change detected, rebuilding site (#1).
2026-05-14 01:20:35.566 +0200
Source changed /news/_index.md
ERROR Rebuild failed: assemble: failed to create page from pageMetaSource /news: "[redacted]/content/news/_index.md:1:1": unable to cast <nil> of type <nil> to map[string]interface {}
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Total in 1 ms

# 5.
Change detected, rebuilding site (#2).
2026-05-14 01:20:38.066 +0200
Source changed /news/_index.md
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Total in 0 ms
panic: interface conversion: *hugolib.pageMetaSource is not hugolib.contentNodeLookupContentNode: missing method lookupContentNode

goroutine 68 [running]:
github.com/gohugoio/hugo/hugolib.contentNodes.lookupContentNode(...)
        github.com/gohugoio/hugo/hugolib/content_map_page_contentnode.go:198
github.com/gohugoio/hugo/hugolib.(*contentNodeShifter).Shift(0xcb3487721e0?, {0x3466e58, 0xcb349a00888}, {0x1, 0x0, 0x0}, 0x0)
        github.com/gohugoio/hugo/hugolib/content_map_page_contentnodeshifter.go:158 +0xd3
github.com/gohugoio/hugo/hugolib/doctree.(*NodeShiftTree[...]).shift(...)
        github.com/gohugoio/hugo/hugolib/doctree/nodeshifttree.go:653
github.com/gohugoio/hugo/hugolib/doctree.(*NodeShiftTreeWalker[...]).toT(0x1000000010000?, 0xcb3483bede0?, {0x3466e58?, 0xcb349a00888?})
        github.com/gohugoio/hugo/hugolib/doctree/nodeshifttree.go:640 +0x68
github.com/gohugoio/hugo/hugolib.(*HugoSites).withPage.(*HugoSites).withPage.(*HugoSites).allSites.func3.(*HugoSites).withPage-range1.(*NodeShiftTreeWalker[...]).Walk.func5.1({0x3466e58, 0xcb349a00888})
        github.com/gohugoio/hugo/hugolib/doctree/nodeshifttree.go:551 +0x125
github.com/gohugoio/hugo/hugolib/doctree.(*walkHandler[...]).Handle(0x163c965?, {0xcb3483bede0?, 0xcb348ea4e70?}, {0x3466e58?, 0xcb349a00888?})
        github.com/gohugoio/hugo/hugolib/doctree/nodeshifttree.go:501 +0x38
github.com/gohugoio/go-radix.recursiveWalk[...](0xcb3493a89c0, {0x3466db8, 0xcb34974e2c0})
        github.com/gohugoio/[email protected]/radix.go:604 +0x89
github.com/gohugoio/go-radix.recursiveWalk[...](0xcb3493a8990, {0x3466db8, 0xcb34974e2c0})
        github.com/gohugoio/[email protected]/radix.go:622 +0x15c
github.com/gohugoio/go-radix.recursiveWalk[...](0xcb3486c6c30, {0x3466db8, 0xcb34974e2c0})
        github.com/gohugoio/[email protected]/radix.go:622 +0x15c
github.com/gohugoio/go-radix.(*Tree[...]).Walk(0x7d148288b528?, {0x3466db8?, 0xcb34974e2c0?})
        github.com/gohugoio/[email protected]/radix.go:504 +0x27
github.com/gohugoio/hugo/hugolib.(*HugoSites).withPage.(*HugoSites).withPage.(*HugoSites).allSites.func3.(*HugoSites).withPage-range1.(*NodeShiftTreeWalker[...]).Walk.func5({0x347d960, 0x581ca20}, 0xcb3489e5bc0, 0x34b3300)
        github.com/gohugoio/hugo/hugolib/doctree/nodeshifttree.go:621 +0x225
github.com/gohugoio/hugo/hugolib/doctree.(*NodeShiftTreeWalker[...]).Walk(...)
        github.com/gohugoio/hugo/hugolib/doctree/nodeshifttree.go:632
github.com/gohugoio/hugo/hugolib.(*HugoSites).withPage-range1(...)
        github.com/gohugoio/hugo/hugolib/hugo_sites.go:602
github.com/gohugoio/hugo/hugolib.(*HugoSites).withPage.(*HugoSites).allSites.func3(...)
        github.com/gohugoio/hugo/hugolib/hugo_sites.go:174
github.com/gohugoio/hugo/hugolib.(*HugoSites).withPage(0x3476ca0?, 0xcb3489e5b90)
        github.com/gohugoio/hugo/hugolib/hugo_sites.go:591 +0x192
github.com/gohugoio/hugo/hugolib.(*HugoSites).resolveAndResetDependententPageOutputs(0xcb348c01688, {0x347d960, 0x581ca20}, {0xcb34952b340, 0x1, 0x1})
        github.com/gohugoio/hugo/hugolib/content_map_page.go:1143 +0x2ca
github.com/gohugoio/hugo/hugolib.(*HugoSites).resolveAndClearStateForIdentities.func5()
        github.com/gohugoio/hugo/hugolib/content_map_page.go:1051 +0x136
github.com/gohugoio/hugo/common/loggers.TimeTrackfn(0xcb3482be7d8)
        github.com/gohugoio/hugo/common/loggers/logger.go:394 +0x35
github.com/gohugoio/hugo/hugolib.(*HugoSites).resolveAndClearStateForIdentities(0xcb348c01688, {0x347d960, 0x581ca20}, {0x3495370, 0xcb3491b5680}, 0x0, {0xcb34952b340, 0x1, 0x1})
        github.com/gohugoio/hugo/hugolib/content_map_page.go:1046 +0x772
github.com/gohugoio/hugo/hugolib.(*HugoSites).processPartialFileEvents(0xcb348c01688, {0x347d960, 0x581ca20}, {0x3495370, 0xcb3491b5680}, 0xcb349584100, 0xcb3482bf558, {0xcb349610140, 0x2, 0x2})
        github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:1190 +0x201c
github.com/gohugoio/hugo/hugolib.(*HugoSites).process(0xcb348c01688, {0x347d960, 0x581ca20}, {0x3495370?, 0xcb3491b5680?}, 0xcb349584100, 0xcb3482bf558, {0xcb349610140, 0x2, 0x2})
        github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:288 +0x265
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build.func6(...)
        github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:170
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build(0xcb348c01688, {0x0, 0x0, 0x0, 0x0, 0xcb34888ed80, 0x0, 0x1, 0x0}, {0xcb349610140, ...})
        github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:186 +0x831
github.com/gohugoio/hugo/commands.(*hugoBuilder).rebuildSites(0xcb348e45280, {0xcb349610140, 0x1, 0x2})
        github.com/gohugoio/hugo/commands/hugobuilder.go:1146 +0x1ed
github.com/gohugoio/hugo/commands.(*hugoBuilder).handleEvents.func7(0xcb348e45280, 0xcb349594060)
        github.com/gohugoio/hugo/commands/hugobuilder.go:949 +0x79
github.com/gohugoio/hugo/commands.(*hugoBuilder).handleEvents(0xcb348e45280, 0xcb349363590, 0xcb3492b6890, {0xcb348b6a3c0, 0x5, 0x8}, 0xcb349371c80)
        github.com/gohugoio/hugo/commands/hugobuilder.go:952 +0x1b85
github.com/gohugoio/hugo/commands.(*hugoBuilder).newWatcher.func2()
        github.com/gohugoio/hugo/commands/hugobuilder.go:393 +0x2aa
created by github.com/gohugoio/hugo/commands.(*hugoBuilder).newWatcher in goroutine 1
        github.com/gohugoio/hugo/commands/hugobuilder.go:364 +0x4d4

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.161.1+extended+withdeploy linux/amd64 BuildDate=unknown VendorInfo=nixpkgs

Does this issue reproduce with the latest release?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions