{"record":{"id":"6d7e5d4e7f9e16f5","repo":"gohugoio/hugo","slug":"meta-init-failed-s","errorCode":null,"errorMessage":"meta init failed: %s","messagePattern":"meta init failed: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/image.go","lineNumber":193,"sourceCode":"\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()\n\tp1, _ := paths.FileAndExt(df.File)\n\th := i.hash()\n\tidStr := hashing.HashStringHex(h, i.size(), imageMetaInfoVersionNumber, cfgHash)\n\tdf.File = fmt.Sprintf(\"%s_%s_meta.json\", p1, idStr)\n\treturn df.TargetPath()\n}\n\n// Colors returns a slice of the most dominant colors in an image","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/image.go#L175-L211","documentation":"Panic in imageResource.Meta() when the lazily-initialized metaInfoFn() returns an error. Hugo decodes general image metadata (dimensions, format) via Imaging.DecodeMeta and caches it; a decode failure or cache I/O error surfaces here as a panic. The underlying error message is included.","triggerScenarios":"Calling .Meta on an image resource that cannot be decoded (corrupt headers, truncated file, unsupported format), or when the metadata cache read/write fails. DecodeMeta returns an error for images it cannot parse.","commonSituations":"A truncated or zero-byte image in assets/images. An unsupported/obscure image format. Cache directory permissions or disk-full conditions. A file with a wrong extension (e.g. .png that is actually a JPEG sometimes mis-decoded).","solutions":["Verify the image file is valid and openable before calling .Meta (decode it locally).","Fix cache directory permissions / free disk space for resources/_gen.","Re-save the image in a supported format (JPEG, PNG, GIF, TIFF, WebP, BMP).","Rename files to match their true format."],"exampleFix":"{{/* before: .Meta panics on a corrupt image */}}\n{{ with $img.Meta }}{{ .Width }}{{ end }}\n\n{{/* after: validate the resource decodes; repair or remove the bad file */}}\n{{ $img := resources.Get \"banner.png\" }}\n{{ if and $img (ne $img.MediaType.SubType \"\") }}\n  {{ with $img.Meta }}{{ .Width }}x{{ .Height }}{{ end }}\n{{ end }}","handlingStrategy":"validation","validationCode":"// Validate the image decodes before calling .Meta.\n// Template: guard with {{ if $img }} and known media type.\n// Go: open and sniff the header to confirm format matches the extension.","typeGuard":null,"tryCatchPattern":"// Meta panics on decode failure; recover to degrade gracefully:\nfunc safeMeta(img *resources.ImageResource) (m *meta.MetaInfo, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"image meta decode failed: %v\", r)\n        }\n    }()\n    return img.Meta(), nil\n}","preventionTips":["Ensure source images are valid and complete.","Keep the cache directory writable with free disk space.","Re-save images in supported formats (JPEG/PNG/GIF/TIFF/WebP/BMP).","Match file extensions to true formats."],"tags":["images","metadata","resources","panic","data-decode"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}