gohugoio/hugo · error
wrapError with nil
Error message
wrapError with nil
What it means
Panic in pageMetaSource.wrapError when called with a nil error. wrapError exists solely to add file/source context to an existing error; a nil argument is a programming mistake in the caller. It is a defensive assertion to prevent silent no-op error wrapping.
Source
Thrown at hugolib/page.go:779
o = append(o, of)
}
return o
}
type renderStringOpts struct {
Display string
Markup string
}
var defaultRenderStringOpts = renderStringOpts{
Display: "inline",
Markup: "", // Will inherit the page's value when not set.
}
func (m *pageMetaSource) wrapError(err error, sourceFs afero.Fs) error {
if err == nil {
panic("wrapError with nil")
}
if m.f == nil {
// No more details to add.
return fmt.Errorf("%q: %w", m.Path(), err)
}
return hugofs.AddFileInfoToError(err, m.f.FileInfo(), sourceFs)
}
// wrapError adds some more context to the given error if possible/needed
func (ps *pageState) wrapError(err error) error {
return ps.m.wrapError(err, ps.s.h.SourceFs)
}
func (ps *pageState) getPageInfoForError() string {
s := fmt.Sprintf("kind: %q, path: %q", ps.Kind(), ps.Path())
if ps.File() != nil {View on GitHub (pinned to 52c9bd7908)
Solutions
- If you see this in Hugo core, file an issue; it is an internal bug — wrapError must only be called with a non-nil error.
- Update Hugo to the latest release where the call-site bug is likely fixed.
- If patching locally, guard the call site: if err != nil { err = ps.wrapError(err) }.
Example fix
// before (Hugo internal call site)
return m.wrapError(err) // err may be nil
// after
if err != nil {
return m.wrapError(err)
}
return nil Defensive patterns
Strategy: validation
Validate before calling
// Hugo internal callers: never call wrapError with a nil error.
// if err != nil { err = ps.wrapError(err) }
// API users cannot trigger this directly; it indicates an internal bug. Prevention
- Guard all wrapError call sites with err != nil.
- Upgrade Hugo when this surfaces.
- Report the call site from the stack trace upstream.
When it happens
Trigger: Hugo internal code calls m.wrapError(err) without first checking err != nil. Typically a logic bug where the error variable is nil at the call site (e.g. a function that returned nil error but the wrap is reached unconditionally).
Common situations: A bug introduced during refactoring of error handling paths. A new code path that wraps unconditionally. Reached only via malformed input that bypasses an earlier error check.
Related errors
- no site
- ContentMediaType not set
- no pageOutput
- pageOutput is nil for output idx %d
- pageMeta.pageMetaSource.pi must be set before creating cache
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/8c78ce47255ed6ba.
Report an issue: GitHub.