{"record":{"id":"e262180ec6f33372","repo":"gohugoio/hugo","slug":"exif-init-failed-s","errorCode":null,"errorMessage":"exif init failed: %s","messagePattern":"exif init failed: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/image.go","lineNumber":185,"sourceCode":"func (i *imageResource) newColorsFn() func() ([]images.Color, error) {\n\treturn sync.OnceValues(func() ([]images.Color, error) {\n\t\timg, err := i.DecodeImage()\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tcolors := color_extractor.ExtractColors(img)\n\t\tresult := make([]images.Color, len(colors))\n\t\tfor j, c := range colors {\n\t\t\tresult[j] = images.ColorGoToColor(c)\n\t\t}\n\t\treturn result, nil\n\t})\n}\n\nfunc (i *imageResource) Exif() *meta.ExifInfo {\n\tx, err := i.root.exifInfoFn()\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"exif init failed: %s\", err))\n\t}\n\treturn x\n}\n\nfunc (i *imageResource) Meta() *meta.MetaInfo {\n\tm, err := i.root.metaInfoFn()\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"meta init failed: %s\", err))\n\t}\n\treturn m\n}\n\nfunc (i *imageResource) getImageMetaInfoCacheTargetPath() string {\n\t// Increment to invalidate the meta cache\n\tconst imageMetaInfoVersionNumber = 1\n\n\tcfgHash := i.getSpec().Imaging.Cfg.SourceHash\n\tdf := i.getResourcePaths()","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/image.go#L167-L203","documentation":"Panic in imageResource.Exif() when the lazily-initialized exifInfoFn() returns an error. Hugo decodes EXIF metadata from the image (via Imaging.DecodeExif) and caches it; if decoding fails (corrupt EXIF, unsupported format, cache I/O error), the error is propagated as a panic from Exif(). The error string from the underlying failure is included.","triggerScenarios":"Calling .Exif on an image resource whose EXIF data is corrupt or unsupported by the decoder, or when the image file cache cannot be read/written. Passing a non-photographic image (SVG, some PNGs) where EXIF decoding fails. Permissions issues on the cache directory.","commonSituations":"A corrupt or truncated JPEG/TIFF uploaded to assets/images. A misconfigured imaging.exif config. Read-only cache filesystem. An image format the EXIF library cannot parse.","solutions":["Validate the image file is a valid JPEG/TIFF with readable EXIF before calling .Exif.","Check filesystem permissions on the Hugo cache directory (often resources/_gen).","Re-export/repair the source image's EXIF, or strip EXIF if you do not need it.","Guard template usage: {{ with .Exif }}...{{ end }} will still panic; instead pre-validate the resource or wrap usage in a partial that checks the image format."],"exampleFix":"{{/* before: .Exif panics on a corrupt image */}}\n{{ with $img.Exif }}{{ .Date }}{{ end }}\n\n{{/* after: only call Exif for known photo formats; repair the source */}}\n{{ if in (slice \"jpg\" \"jpeg\" \"tiff\") $img.MediaType.SubType }}\n  {{ with $img.Exif }}{{ .Date }}{{ end }}\n{{ end }}","handlingStrategy":"validation","validationCode":"// Validate the image is a photo format with readable EXIF before calling .Exif.\n// Template side: gate on media type.\n// Go side: decode a probe to ensure the file is a valid JPEG/TIFF.\nfunc hasExif(subType string) bool {\n    switch subType {\n    case \"jpeg\", \"jpg\", \"tiff\":\n        return true\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"// Exif panics on decode failure; recover to degrade gracefully:\nfunc safeExif(img *resources.ImageResource) (exif *meta.ExifInfo, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"exif decode failed: %v\", r)\n        }\n    }()\n    return img.Exif(), nil\n}","preventionTips":["Only call .Exif on JPEG/TIFF resources.","Keep the cache directory writable.","Repair/strip EXIF on corrupt source images.","Validate uploads before they enter assets/."],"tags":["images","exif","resources","panic","data-decode"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}