gohugoio/hugo · error

failed to read page content: %w

Error message

failed to read page content: %w

What it means

Returned by ParseFrontMatterAndContent (parser/pageparser/pageparser.go:63) when io.ReadAll on the supplied reader fails before any parsing happens. It is an I/O failure reading the raw page bytes, not a front matter syntax error — those surface from ParseBytes afterwards.

Source

Thrown at parser/pageparser/pageparser.go:63

		return nil, err
	}
	return l.items, l.err
}

type ContentFrontMatter struct {
	Content           []byte
	FrontMatter       map[string]any
	FrontMatterFormat metadecoders.Format
}

// ParseFrontMatterAndContent is a convenience method to extract front matter
// and content from a content page.
func ParseFrontMatterAndContent(r io.Reader) (ContentFrontMatter, error) {
	var cf ContentFrontMatter

	input, err := io.ReadAll(r)
	if err != nil {
		return cf, fmt.Errorf("failed to read page content: %w", err)
	}

	psr, err := ParseBytes(input, Config{})
	if err != nil {
		return cf, err
	}

	var frontMatterSource []byte

	iter := NewIterator(psr)

	walkFn := func(item Item) bool {
		if frontMatterSource != nil {
			// The rest is content.
			cf.Content = input[item.low:]
			// Done
			return false
		} else if item.IsFrontMatter() {

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Check the wrapped error for the OS-level cause (permission denied, input/output error).
  2. Verify file permissions and ownership of the content file: ls -l content/...
  3. If the file lives on a sync/network mount, ensure it is fully hydrated locally before building.
  4. Re-run the command; if it persists, copy the file locally to rule out filesystem faults.
Defensive patterns

Strategy: validation

Validate before calling

fi, err := os.Stat(path)
if err != nil { return err }
if !fi.Mode().IsRegular() {
    return fmt.Errorf("%s: not a regular file", path)
}
// ensure the reader you pass is fresh and not already consumed/closed

Try / catch

items, err := pageparser.ParseBytes(b, cfg)
if err != nil {
    return fmt.Errorf("parse %s: %w", path, err)
}

Prevention

When it happens

Trigger: Any caller of pageparser.ParseFrontMatterAndContent (e.g. hugo import/convert commands, tooling embedding Hugo) passing a reader whose Read errors: a closed or unreadable file handle, a failing network/pipe reader, or a filesystem error mid-read.

Common situations: Content files with permission problems, files on network mounts or synced folders (Dropbox/OneDrive placeholders) that error on read, files deleted between stat and read during `hugo convert`, or truncated/locked files on Windows.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/4b79777d306e18a9.json. Report an issue: GitHub ↗.