{"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":"error","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/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/images/image.go#L103-L139","documentation":"Hugo panics with this error in Image.initConfig when it lazily decodes an image's header (dimensions/format) via Codec.DecodeConfig and the read or decode fails. The config is loaded on first access to properties like .Width/.Height, so a corrupt or unreadable image surfaces here rather than at resource-open time. The wrapped error carries the underlying cause (I/O error or malformed image data).","triggerScenarios":"Calling .Width, .Height, or an image processing method (.Resize, .Fit, etc.) in a template on an image resource whose bytes cannot be decoded — truncated file, wrong magic bytes for its extension, unsupported/corrupt encoding — or whose ReadSeekCloser fails to open.","commonSituations":"Corrupted images committed to assets/ or static/; files with an image extension that are actually HTML (e.g. a saved 404 page from a broken download); Git LFS pointer files not pulled so the 'image' is a tiny text stub; SVG or unsupported formats renamed with .png/.jpg extensions.","solutions":["Identify the offending image from the surrounding error context and verify it opens in an image viewer or with `file <path>` — replace it if corrupt.","If using Git LFS, run `git lfs pull` so real binaries, not pointer stubs, are present in CI.","Ensure the file's actual format matches one Hugo can decode (jpeg, png, gif, tiff, bmp, webp, avif); re-export from your editor if not.","Guard templates against non-image resources before calling image methods: `{{ with .Resources.GetMatch \"cover.*\" }}{{ if eq .ResourceType \"image\" }}...{{ end }}{{ end }}`."],"exampleFix":"// before: LFS pointer stub committed instead of binary\n// assets/img/hero.jpg -> \"version https://git-lfs.github.com/spec/v1...\"\n$ git lfs pull\n// after: real JPEG bytes present, {{ $img.Width }} works","handlingStrategy":"try-catch","validationCode":"// Verify the file decodes as an image before processing\nf, err := os.Open(path)\nif err != nil { return err }\ndefer f.Close()\nif _, _, err := image.DecodeConfig(f); err != nil {\n    return fmt.Errorf(\"invalid or unsupported image %q: %w\", path, err)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"failed to load image config\") {\n    // corrupt/truncated file or unregistered format — skip or report the asset\n}","preventionTips":["Validate uploaded/fetched images with image.DecodeConfig before handing them to the pipeline","Check file extensions match actual content (magic bytes), not just the filename","Guard against zero-byte or truncated downloads before processing"],"tags":["hugo","images","decode","assets"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}