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

Skip to content

Index out of range panic when multiple content directories with different nesting levels are created together #14573

@cj123

Description

@cj123

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

$ hugo version
hugo v0.157.0+extended+withdeploy darwin/arm64 BuildDate=2026-02-25T16:38:33Z VendorInfo=Homebrew

Does this issue reproduce with the latest release?

Yes

Steps to reproduce

The following bash script is the simplest cause of the panic I have been able to reproduce in a new hugo site, but I have also seen this panic running in production when automated processes create a number of files together.

#!/bin/bash

mkdir -p content/nesteddir/dir1

echo "content" >>content/nesteddir/dir1/post.md

mkdir -p content/dir{1..2}

To reproduce:

  1. In a new hugo site, ensure content directory is empty
  2. Run hugo build -w
  3. In another terminal session, run the bash script above, e.g. ./create-content.sh
  4. Panic occurs.

After this, if hugo build -w is re-run, the site builds correctly, including the new pages.

Panic Output

adding created directory to watchlist <dir>/content/nesteddir
adding created directory to watchlist <dir>/content/nesteddir/dir1
adding created directory to watchlist <dir>/content/dir1
adding created directory to watchlist <dir>/content/dir2

Change detected, rebuilding site (#1).
2026-02-27 00:03:58.983 +0000
Source changed /nesteddir/dir1/post.md
Source changed /dir1
Source changed /dir2
Source changed /nesteddir
Total in 1 ms
panic: runtime error: index out of range [1] with length 1

goroutine 29 [running]:
github.com/gohugoio/hugo/hugolib.(*HugoSites).fileEventsContentPaths(0x7a77afe88bb0?, {0x7a77aff8ad80?, 0x14?, 0xa?})
	github.com/gohugoio/hugo/hugolib/site.go:1323 +0xa10
github.com/gohugoio/hugo/hugolib.(*HugoSites).processPartialFileEvents(0x7a77afc0a908, {0x1052e6ce0, 0x105b626e0}, {0x1052fb090, 0x7a77af831d40}, 0x7a77aff8ac40, 0x7a77af45d5a8, {0x7a77afb74000, 0x4, 0x4})
	github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:1162 +0x17bc
github.com/gohugoio/hugo/hugolib.(*HugoSites).process(0x7a77afc0a908, {0x1052e6ce0, 0x105b626e0}, {0x1052fb090?, 0x7a77af831d40?}, 0x7a77aff8ac40, 0x7a77af45d5a8, {0x7a77afb74000, 0x4, 0x4})
	github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:288 +0x1ac
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(0x7a77afc0a908, {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0}, {0x7a77afb74000, ...})
	github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:186 +0x5f8
github.com/gohugoio/hugo/commands.(*hugoBuilder).rebuildSites(0x7a77afc33580, {0x7a77afb74000, 0x4, 0x4})
	github.com/gohugoio/hugo/commands/hugobuilder.go:1159 +0x134
github.com/gohugoio/hugo/commands.(*hugoBuilder).handleEvents.func7(0x7a77afc33580, 0x7a77aff0faa0)
	github.com/gohugoio/hugo/commands/hugobuilder.go:948 +0x70
github.com/gohugoio/hugo/commands.(*hugoBuilder).handleEvents(0x7a77afc33580, 0x7a77b00d9290, 0x7a77afe421b8, {0x7a77afd08820, 0x3, 0x4}, 0x7a77b00d9320)
	github.com/gohugoio/hugo/commands/hugobuilder.go:951 +0x14ec
github.com/gohugoio/hugo/commands.(*hugoBuilder).newWatcher.func2()
	github.com/gohugoio/hugo/commands/hugobuilder.go:392 +0x1bc
created by github.com/gohugoio/hugo/commands.(*hugoBuilder).newWatcher in goroutine 1
	github.com/gohugoio/hugo/commands/hugobuilder.go:363 +0x3e8

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions