{"id":"72e4ee493221dcda","repo":"gohugoio/hugo","slug":"failed-to-open-image-for-decode-w","errorCode":null,"errorMessage":"failed to open image for decode: %w","messagePattern":"failed to open image for decode: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/image.go","lineNumber":475,"sourceCode":"\t\ttargetPath := i.relTargetPathFromConfig(conf, i.getSpec().Imaging.Cfg.SourceHash)\n\t\tci.setTargetPath(targetPath)\n\t\tci.Format = conf.TargetFormat\n\t\tci.setMediaType(conf.TargetFormat.MediaType())\n\n\t\treturn ci, converted, nil\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn img, nil\n}\n\n// DecodeImage decodes the image source into an Image.\n// This for internal use only.\nfunc (i *imageResource) DecodeImage() (image.Image, error) {\n\tf, err := i.ReadSeekCloser()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open image for decode: %w\", err)\n\t}\n\tdefer f.Close()\n\n\treturn i.getSpec().Imaging.Codec.DecodeFormat(i.Format, f)\n}\n\nfunc (i *imageResource) clone(img image.Image) *imageResource {\n\tspec := i.baseResource.Clone().(baseResource)\n\n\tvar image *images.Image\n\tif img != nil {\n\t\timage = i.WithImage(img)\n\t} else {\n\t\timage = i.WithSpec(spec)\n\t}\n\n\tir := &imageResource{\n\t\tImage:        image,","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/image.go#L457-L493","documentation":"Raised by imageResource.DecodeImage when i.ReadSeekCloser() fails, i.e. Hugo cannot open the underlying image file/stream before decoding it for a processing operation. It wraps the filesystem or resource-open error; the decode itself never starts.","triggerScenarios":"Any image transform (Resize, Fill, Filter, etc.) triggers doWithImageConfig → DecodeImage; the error fires when opening the source via ReadSeekCloser fails — file deleted/moved mid-build, permission denied, or a broken mounted/remote resource backing the image.","commonSituations":"Files removed while the dev server rebuilds, broken symlinks in assets/, permission problems in CI/containers, cloud-synced folders (Dropbox/OneDrive placeholders) where the file isn't actually on disk, or exhausted file descriptors on very large sites.","solutions":["Inspect the wrapped error for the OS-level cause (ENOENT, EACCES) and confirm the file exists at the expected path","Fix file permissions or restore the missing/placeholder file (force cloud-sync download)","Restart `hugo server` if files changed on disk mid-build","Check module/mount configuration if the image comes from a mounted or module filesystem"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"{{ $img := resources.Get \"photo.jpg\" }}{{ if and $img (eq (index (split $img.MediaType.Type \"/\") 0) \"image\") }}{{/* safe to decode */}}{{ end }}","typeGuard":null,"tryCatchPattern":"{{ with try ($img.Resize \"400x\") }}{{ with .Err }}{{ errorf \"decode failed for %s: %s\" $img.Name . }}{{ end }}{{ end }}","preventionTips":["Check resources.Get / .Resources.GetMatch returned non-nil before decoding","Ensure files with image extensions actually contain valid image data (guard against 0-byte or HTML-error-page downloads)","For remote images fetched with resources.GetRemote, check .Err before piping into image operations","Restrict to formats Hugo can decode: JPEG, PNG, GIF, TIFF, BMP, WebP"],"tags":["hugo","image-processing","filesystem","io"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}