gohugoio/hugo · error
metadata decoding failed: %v
Error message
metadata decoding failed: %v
What it means
Decoder.DecodeMeta decodes metadata from all sources (EXIF, IPTC, XMP) and, like Decode, wraps the whole operation in a deferred recover(). This error means the imagemeta library panicked while parsing one of those metadata blocks and Hugo surfaced the panic as an error rather than crashing.
Source
Thrown at resources/images/meta/meta.go:305
tags := make(map[string]any)
for k, v := range tagInfos.All() {
if !d.shouldIncludeField(k) {
continue
}
tags[k] = v.Value
}
ex = &ExifInfo{Lat: lat, Long: long, Date: tm, Tags: tags}
return
}
// DecodeMeta decodes metadata from all sources (EXIF, IPTC, XMP).
// Filename is only used for logging.
func (d *Decoder) DecodeMeta(filename string, format imagemeta.ImageFormat, r io.Reader) (m *MetaInfo, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("metadata decoding failed: %v", r)
}
}()
var tagInfos imagemeta.Tags
handleTag := func(ti imagemeta.TagInfo) error {
tagInfos.Add(ti)
return nil
}
shouldHandleTag := func(ti imagemeta.TagInfo) bool {
// For EXIF, only include tags from IFD0 (skip thumbnail data).
if ti.Source == imagemeta.EXIF {
if !strings.HasPrefix(ti.Namespace, "IFD0") {
return false
}
}
return d.shouldIncludeField(ti.Tag)View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Find the named file in the log and strip or rewrite its metadata (`exiftool -all= file.jpg`), then rebuild.
- Confirm the file is intact and its extension matches its real format.
- Upgrade Hugo to pick up imagemeta parser fixes; report reproducible panics upstream with the image attached.
Defensive patterns
Strategy: try-catch
Try / catch
md, err := decodeMetadata(r)
if err != nil {
log.Printf("metadata decode failed for %s: %v", name, err)
// treat image as having no metadata; do not abort processing
} Prevention
- Verify image files are not truncated (compare byte size, run `identify`/`exiftool` in a pre-commit check)
- Strip or normalize metadata with exiftool for images from untrusted sources
- Guard template metadata access with existence checks before dereferencing fields
When it happens
Trigger: Accessing an image resource's full metadata (the newer meta API covering EXIF+IPTC+XMP) on a file whose metadata segment triggers a parser panic — malformed XMP XML packets, corrupt IPTC records, or broken EXIF IFDs.
Common situations: Images processed by asset pipelines that write nonstandard XMP, stock photos with vendor-specific IPTC blocks, truncated downloads, or regressions/changes after a Hugo upgrade bumped the bundled imagemeta version.
Related errors
- exif failed: %v
- config needs a filename
- must provide an image and one or more filters
- cannot encode an empty string
- error correction level must be one of low, medium, quartile,
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/cf8fab3da129ed2e.json.
Report an issue: GitHub ↗.