{"record":{"id":"71b4a0e046cc4868","repo":"gohugoio/hugo","slug":"failed-to-load-image-config-w","errorCode":null,"errorMessage":"failed to load image config: %w","messagePattern":"failed to load image config: %w","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"resources/images/image.go","lineNumber":121,"sourceCode":"\tvar err error\n\ti.configInit.Do(func() {\n\t\tif i.configLoaded {\n\t\t\treturn\n\t\t}\n\n\t\tvar f hugio.ReadSeekCloser\n\n\t\tf, err = i.Spec.ReadSeekCloser()\n\t\tif err != nil {\n\t\t\treturn\n\t\t}\n\t\tdefer f.Close()\n\n\t\ti.config, _, err = i.Proc.Codec.DecodeConfig(i.Format, f)\n\t})\n\n\tif err != nil {\n\t\tpanic(fmt.Errorf(\"failed to load image config: %w\", err))\n\t}\n}\n\nfunc NewImageProcessor(debugl, warnl logg.LevelLogger, wasmDispatchers *warpc.Dispatchers, cfg *config.ConfigNamespace[ImagingConfig, ImagingConfigInternal]) (*ImageProcessor, error) {\n\te := cfg.Config.Imaging.Exif\n\texifDecoder, err := meta.NewDecoder(\n\t\tmeta.WithDateDisabled(e.DisableDate),\n\t\tmeta.WithLatLongDisabled(e.DisableLatLong),\n\t\tmeta.ExcludeFields(e.ExcludeFields),\n\t\tmeta.IncludeFields(e.IncludeFields),\n\t\tmeta.WithWarnLogger(warnl),\n\t)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tm := cfg.Config.Imaging.Meta\n\tmetaDecoder, err := meta.NewDecoder(","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/images/image.go#L103-L139","documentation":"A panic (not a returned error) raised by Image.initConfig() when the image codec's DecodeConfig fails — meaning Hugo could not read the image's dimensions or format header. The panic fires lazily on first access to the image config (via sync.Once), and is NOT recovered within this function, so it will crash the build unless caught upstream.","triggerScenarios":"Hugo encounters a corrupt, truncated, or zero-byte image file when it needs to read the image dimensions (e.g. for responsive image markup, resizing, or layout). The panic occurs at image.go:121 inside initConfig, triggered when configLoaded is false and DecodeConfig returns an error.","commonSituations":"A partially downloaded or uploaded image asset; a file with a correct extension (.jpg, .png) but wrong or corrupt content; a CI environment where an image asset was not checked in or was corrupted by Git LFS; switching image processing libraries or Hugo versions that change supported formats.","solutions":["Identify which image file triggered the panic from the build output or stack trace, then open the file in an image viewer to confirm it is corrupt.","Re-export or re-save the image from the original source, or replace it with a known-good copy.","Verify the file extension matches the actual format (e.g. a WEBP file renamed to .png).","Run 'file path/to/image.jpg' or 'identify path/to/image.jpg' (ImageMagick) to confirm the file is a valid image of the expected type."],"exampleFix":"# The error is in an image asset, not code.\n# Verify the file integrity:\n# before: corrupt or truncated file at assets/images/hero.jpg\n# after: re-export from source and replace the file\n\n# Quick check from shell:\n# file assets/images/hero.jpg\n# identify assets/images/hero.jpg","handlingStrategy":"try-catch","validationCode":"// Pre-validate image files before Hugo processes them.\n// In Go, if using Hugo as a library, decode the config yourself first:\nfunc checkImageDecodable(codec Codec, format Format, r io.Reader) error {\n    _, _, err := codec.DecodeConfig(format, r)\n    return err\n}\n\n// From the shell, validate all images before building:\n// find assets/ static/ -type f \\( -name '*.jpg' -o -name '*.png' -o -name '*.webp' \\) -exec identify {} \\; >/dev/null","typeGuard":null,"tryCatchPattern":"// If using Hugo as a Go library, wrap image processing in a recover\ndefer func() {\n    if r := recover(); r != nil {\n        log.Printf(\"image processing panicked (likely corrupt image): %v\", r)\n        // fall back to a placeholder or skip the image\n    }\n}()\nimg.initConfig() // may panic on corrupt images","preventionTips":["Run 'identify <file>' (ImageMagick) or 'file <file>' on all image assets in CI before the Hugo build.","Ensure Git LFS files are fully pulled in CI ('git lfs pull') before building.","Validate image files after downloading from CMS APIs before writing them to the assets directory.","Use 'hugo --logLevel debug' to get more context about which image triggers the panic."],"tags":["hugo","imaging","panic","corrupt-file","crash"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}