{"record":{"id":"4b79777d306e18a9","repo":"gohugoio/hugo","slug":"failed-to-read-page-content-w","errorCode":null,"errorMessage":"failed to read page content: %w","messagePattern":"failed to read page content: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"parser/pageparser/pageparser.go","lineNumber":63,"sourceCode":"\t\treturn nil, err\n\t}\n\treturn l.items, l.err\n}\n\ntype ContentFrontMatter struct {\n\tContent           []byte\n\tFrontMatter       map[string]any\n\tFrontMatterFormat metadecoders.Format\n}\n\n// ParseFrontMatterAndContent is a convenience method to extract front matter\n// and content from a content page.\nfunc ParseFrontMatterAndContent(r io.Reader) (ContentFrontMatter, error) {\n\tvar cf ContentFrontMatter\n\n\tinput, err := io.ReadAll(r)\n\tif err != nil {\n\t\treturn cf, fmt.Errorf(\"failed to read page content: %w\", err)\n\t}\n\n\tpsr, err := ParseBytes(input, Config{})\n\tif err != nil {\n\t\treturn cf, err\n\t}\n\n\tvar frontMatterSource []byte\n\n\titer := NewIterator(psr)\n\n\twalkFn := func(item Item) bool {\n\t\tif frontMatterSource != nil {\n\t\t\t// The rest is content.\n\t\t\tcf.Content = input[item.low:]\n\t\t\t// Done\n\t\t\treturn false\n\t\t} else if item.IsFrontMatter() {","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/parser/pageparser/pageparser.go#L45-L81","documentation":"Returned by pageparser.ParseFrontMatterAndContent when io.ReadAll fails to consume the provided io.Reader. This wraps the underlying I/O error (e.g. a broken pipe, premature close, or failed network read) with %w so callers can unwrap it. The function reads the entire content stream into memory before lexing front matter, so any read fault anywhere in the stream surfaces here.","triggerScenarios":"Calling pageparser.ParseFrontMatterAndContent(r) where r is an io.Reader whose Read returns an error before EOF -- e.g. a bytes.Reader that's fine, but a network-backed reader, a gzip.Reader on truncated data, or a file Reader on a disk that hits an I/O error mid-read.","commonSituations":"Content served over an unreliable stream, a content file that is concurrently truncated/rotated, a reader wrapping a tar/gzip stream that ends unexpectedly, or a custom io.Reader implementation that returns an error instead of io.EOF.","solutions":["Verify the io.Reader is fully readable before passing it in (e.g. buffer it with a bytes.Buffer or io.ReadAll upstream and handle errors there).","If reading from a file, check file permissions, that the file is not being written/rotated concurrently, and that it is not truncated.","Unwrap the error with errors.Is/errors.As to distinguish a transient I/O fault from a permanent one and decide whether to retry the read."],"exampleFix":"// before\nr := openUnreliableReader()\ncf, err := pageparser.ParseFrontMatterAndContent(r)\nif err != nil { return err }\n\n// after: buffer first so read errors surface explicitly\nbuf, err := io.ReadAll(openUnreliableReader())\nif err != nil { return fmt.Errorf(\"prefetch content: %w\", err) }\ncf, err := pageparser.ParseFrontMatterAndContent(bytes.NewReader(buf))\nif err != nil { return err }","handlingStrategy":"validation","validationCode":"// Pre-buffer the reader so parse errors are decoupled from read errors.\nfunc safeParse(r io.Reader) (pageparser.ContentFrontMatter, error) {\n    b, err := io.ReadAll(r)\n    if err != nil {\n        return pageparser.ContentFrontMatter{}, fmt.Errorf(\"prefetch content: %w\", err)\n    }\n    if len(b) == 0 {\n        return pageparser.ContentFrontMatter{}, errors.New(\"empty content input\")\n    }\n    return pageparser.ParseFrontMatterAndContent(bytes.NewReader(b))\n}","typeGuard":null,"tryCatchPattern":"if cf, err := pageparser.ParseFrontMatterAndContent(r); err != nil {\n    var pathErr *fs.PathError\n    if errors.As(err, &pathErr) { /* handle file-level fault */ }\n    return err\n} else { use(cf) }","preventionTips":["Buffer untrusted/streaming readers into a []byte before calling parse functions.","Never pass a reader that may be closed concurrently.","Log the unwrapped error to distinguish read faults from parse faults."],"tags":["parser","io","front-matter","content-reading"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}