gohugoio/hugo · error
failed to load CODEOWNERS
Error message
failed to load CODEOWNERS: %w
What it means
Raised at page__new.go:95 when HugoSites.codeownersForPage cannot resolve CODEOWNERS data for a page. codeownersForPage triggers the same one-shot gitInfo init that loadGitInfo (hugo_sites.go:546) runs; newCodeOwners (codeowners.go:54) finds and parses the CODEOWNERS file. The wrapped error is the parse/IO failure.
Solutions
- Open the CODEOWNERS file and fix the offending line flagged by the wrapped error (commonly a malformed glob or missing owner).
- If CODEOWNERS metadata is not needed, set `enableGitInfo = false` or remove/rename the CODEOWNERS file so it is not picked up.
- Validate the file against GitHub's CODEOWNERS syntax and simplify any advanced patterns.
Example fix
# before (CODEOWNERS with bad line) /src/ @team-a not-an-owner # after /src/ @team-a @team-b
Defensive patterns
Strategy: validation
Validate before calling
# If you ship a CODEOWNERS file, lint it as part of CI.
# A minimal check: every non-comment line must end with at least one owner token.
awk 'NF && $1 !~ /^#/ && NF < 2 {print FILENAME ":" NR ": missing owner"; exit 1}' CODEOWNERS Prevention
- Keep CODEOWNERS syntax simple (path-pattern followed by @user/@team tokens).
- If CODEOWNERS is not needed, do not enable enableGitInfo or remove the file.
- Add a CI lint step for CODEOWNERS to catch malformed rules before Hugo runs.
When it happens
Trigger: enableGitInfo = true is set and a CODEOWNERS file exists but is malformed (bad pattern, unparseable line); the CODEOWNERS file cannot be read due to permissions; the codeowners library rejects a rule syntax it does not support.
Common situations: Adopting CODEOWNERS in a Hugo project with a hand-edited file that contains a syntax the parser rejects; a CODEOWNERS inherited from GitHub with a feature Hugo's parser does not support; file permission issues in containerized builds.
Related errors
- failed to load Git data
- babel config not found
- cannot use --renderToMemory with --destination
- cardinalityThreshold threshold must be between 0 and 100
- exif failed
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/d0ff64db6fcbb1bf.
Report an issue: GitHub.
Appendix: 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 52c9bd7908)