gohugoio/hugo · error
failed to load CODEOWNERS: %w
Error message
failed to load CODEOWNERS: %w
What it means
When a CODEOWNERS file is configured/present, Hugo maps each content file to its owners via `codeownersForPage` during page construction so templates can use `.CodeOwners`. If parsing the CODEOWNERS file or matching the page's path fails, page creation stops with this wrapped error.
Source
Thrown at hugolib/page__new.go:95
},
}
if ps.IsHome() && ps.PathInfo().IsLeafBundle() {
msg := "Using %s in your content's root directory is usually incorrect for your home page. "
msg += "You should use %s instead. If you don't rename this file, your home page will be "
msg += "treated as a leaf bundle, meaning it won't be able to have any child pages or sections."
ps.s.Log.Warnidf(constants.WarnHomePageIsLeafBundle, msg, ps.PathInfo().PathNoLeadingSlash(), strings.ReplaceAll(ps.PathInfo().PathNoLeadingSlash(), "index", "_index"))
}
if m.f != nil {
gi, err := s.h.gitInfoForPage(ps)
if err != nil {
return nil, fmt.Errorf("failed to load Git data: %w", err)
}
ps.gitInfo = gi
owners, err := s.h.codeownersForPage(ps)
if err != nil {
return nil, fmt.Errorf("failed to load CODEOWNERS: %w", err)
}
ps.codeowners = owners
}
ps.pageMenus = &pageMenus{p: ps}
ps.PageMenusProvider = ps.pageMenus
ps.GetPageProvider = pageSiteAdapter{s: s, p: ps}
ps.GitInfoProvider = ps
ps.TranslationsProvider = ps
ps.ResourceDataProvider = newDataFunc(ps)
ps.RawContentProvider = ps
ps.ChildCareProvider = ps
ps.TreeProvider = pageTree{p: ps}
ps.Eqer = ps
ps.TranslationKeyProvider = ps
ps.ShortcodeInfoProvider = ps
ps.AlternativeOutputFormatsProvider = ps
View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Read the wrapped error to find the offending CODEOWNERS line and fix its pattern syntax (standard gitignore-style patterns plus owner handles).
- Validate the file with a CODEOWNERS linter or GitHub's own validation view.
- If codeowners data isn't wanted in the build, remove/rename the CODEOWNERS file from the build context.
Defensive patterns
Strategy: validation
Validate before calling
# Verify CODEOWNERS parses before enabling codeowners support: test -f CODEOWNERS || test -f .github/CODEOWNERS # Check each non-comment line is '<pattern> <owner>...' with no stray tokens
Try / catch
if err := build(); err != nil {
if strings.Contains(err.Error(), "CODEOWNERS") {
log.Println("fix CODEOWNERS syntax or remove the file / disable the feature")
}
return err
} Prevention
- Lint CODEOWNERS in CI (GitHub validates it; use a codeowners linter locally)
- Keep CODEOWNERS in a standard location (repo root, .github/, or docs/)
- Only enable Hugo's codeowners page variable when the file exists and is valid
- Avoid unsupported glob syntax in patterns
When it happens
Trigger: A build where a `CODEOWNERS` file exists (repo root, `.github/`, or `docs/`) and the codeowners parser fails on it — malformed pattern lines, unreadable file, or an error resolving the page's filename against the ruleset in `newPageFromMeta` (hugolib/page__new.go:93-96).
Common situations: Hand-edited CODEOWNERS with syntax GitHub tolerates but the Go codeowners parser rejects; encoding issues (BOM, CRLF oddities); CODEOWNERS copied from another tool with unsupported pattern syntax; file permission problems in containers.
Related errors
- error processing file %q
- failed to parse file %q: %s
- error copying static files: %w
- error building site: %w
- failed to compile cache buster %q: %w
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/d0ff64db6fcbb1bf.json.
Report an issue: GitHub ↗.