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
- Check the wrapped error for the OS-level cause (permission denied, input/output error).
- Verify file permissions and ownership of the content file: ls -l content/...
- If the file lives on a sync/network mount, ensure it is fully hydrated locally before building.
- 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
- Verify content files are readable regular files (not sockets/dirs/broken symlinks) before parsing
- Pass a fresh io.Reader; don't reuse a reader that may already be drained or closed
- Guard against truncated/partial writes: write content files atomically (temp file + rename)
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
- error processing file %q
- error building site: %w
- no existing content directory configured for this project
- failed to resolve %q to an archetype template
- failed to create target directory for %q: %w
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/4b79777d306e18a9.json.
Report an issue: GitHub ↗.