Panic after command

Should this be happening? Or am I using the --panicOnWarning wrongly?

$ hugo --printUnusedTemplates --panicOnWarning
Start building sites … 
hugo v0.167.0-3fff6fb5c267dacb26280c78dbe8c344054249c8+extended linux/amd64 BuildDate=2026-09-28T14:50:38Z VendorInfo=gohugoio

WARN  Template /_partials/author_pages.html is unused, source ".../layouts/_partials/author_pages.html"
panic: Template /_partials/author_pages.html is unused, source "/.../layouts/_partials/author_pages.html"

goroutine 20 [running]:
github.com/gohugoio/hugo/common/loggers.init.func1(0x2657a2ca0750?)
	/root/project/hugo/common/loggers/handlersmisc.go:32 +0x3e
github.com/gohugoio/hugo/common/loggers.New.func2(0x2657b16b17c8?)
	/root/project/hugo/common/loggers/logger.go:93 +0x17
github.com/bep/logg.HandlerFunc.HandleLog(0x2657a00b6120?, 0x2657a7a6eae0?)
	/root/project/gomodcache/github.com/bep/logg@v0.4.0/handler.go:26 +0x19
github.com/bep/logg/handlers/multi.(*Handler).HandleLog(0x2657a0482af8?, 0x2657a7a6eae0)
	/root/project/gomodcache/github.com/bep/logg@v0.4.0/handlers/multi/multi.go:26 +0x4e
github.com/gohugoio/hugo/common/loggers.(*stopHandler).HandleLog(0x2657a0498fc0?, 0x2657a7a6eae0)
	/root/project/hugo/common/loggers/handlersmisc.go:109 +0x54
github.com/bep/logg.(*logger).log(0x2657a00b61e0, 0x2657a0498fc0, {0x3137f58, 0x2657ac46e8a0})
	/root/project/gomodcache/github.com/bep/logg@v0.4.0/logger.go:154 +0x105
github.com/bep/logg.(*Entry).Logf(0x2657a0498fc0, {0x19e62cf, 0x20}, {0x2657a5b60a20, 0x2, 0x2})
	/root/project/gomodcache/github.com/bep/logg@v0.4.0/entry.go:113 +0xb8
github.com/gohugoio/hugo/common/loggers.(*logAdapter).Warnf(0x2657a005f650?, {0x19e62cf?, 0x2657a0498f00?}, {0x2657a5b60a20?, 0x193d780?, 0x3f841e0?})
	/root/project/hugo/common/loggers/logger.go:313 +0x2c
github.com/gohugoio/hugo/hugolib.(*HugoSites).printUnusedTemplatesOnce.func1()
	/root/project/hugo/hugolib/hugo_sites_build.go:639 +0x1a3
sync.(*Once).doSlow(0xffffffffffffffff?, 0x0?)
	/usr/local/go/src/sync/once.go:78 +0xab
sync.(*Once).Do(...)
	/usr/local/go/src/sync/once.go:69
github.com/gohugoio/hugo/hugolib.(*HugoSites).printUnusedTemplatesOnce(0x2657a089d8c8?)
	/root/project/hugo/hugolib/hugo_sites_build.go:633 +0x3b
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build(0x2657a089d8c8, {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, {0x0, ...})
	/root/project/hugo/hugolib/hugo_sites_build.go:217 +0xd97
github.com/gohugoio/hugo/commands.(*hugoBuilder).buildSites(0x0?, 0x0)
	/root/project/hugo/commands/hugobuilder.go:451 +0x105
github.com/gohugoio/hugo/commands.(*hugoBuilder).fullBuild.func3()
	/root/project/hugo/commands/hugobuilder.go:625 +0x1f
golang.org/x/sync/errgroup.(*Group).Go.func1()
	/root/project/gomodcache/golang.org/x/sync@v0.23.0/errgroup/errgroup.go:93 +0x50
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 1
	/root/project/gomodcache/golang.org/x/sync@v0.23.0/errgroup/errgroup.go:78 +0xa5

Exactly as you requested:

  • without the command line parameters hugo just ignores unused templates

  • --printUnusedTemplates instructs to print a warning for each unused template
    which results in line 5 (WARN Template...)

  • --panicOnWarning panics if any warning has been detected
    which results in line 6 (panic: Template ...)

    and if hugo panics a stacktrace is printed which results in lines lines 8+

  • looks like it does not collect all warnings and panics at the end but immediately does. Maybe for other types of warnings you could get more warnings before the panic bacause of concurrency; unsure about that.