{"id":"25cb55469cfeb04b","repo":"gohugoio/hugo","slug":"failed-to-s-image-q-w","errorCode":null,"errorMessage":"failed to %s image %q: %w","messagePattern":"failed to (.+?) image %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/image.go","lineNumber":363,"sourceCode":"\t\t\t\t\torientation = meta.Orientation\n\t\t\t\t}\n\t\t\t\tif tf := orientationProvider.AutoOrient(orientation); tf != nil {\n\t\t\t\t\tfilters = append(filters, tf)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfilters = append(filters, f)\n\t\t\t}\n\t\t}\n\t\treturn i.Proc.Filter(src, filters...)\n\t})\n}\n\nfunc (i *imageResource) processActionSpec(action, spec string) (images.ImageResource, error) {\n\toptions := append([]string{action}, strings.Fields(strings.ToLower(spec))...)\n\tir, err := i.processOptions(options)\n\tif err != nil {\n\t\tif sourcePath := i.sourcePath(); sourcePath != \"\" {\n\t\t\terr = fmt.Errorf(\"failed to %s image %q: %w\", action, sourcePath, err)\n\t\t}\n\t\treturn nil, err\n\t}\n\treturn ir, nil\n}\n\nfunc (i *imageResource) processOptions(options []string) (images.ImageResource, error) {\n\tconf, err := images.DecodeImageConfig(options, i.Proc.Cfg, i.Format)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\timg, err := i.doWithImageConfig(conf, func(src image.Image) (image.Image, error) {\n\t\treturn i.Proc.ApplyFiltersFromConfig(src, conf)\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/image.go#L345-L381","documentation":"Wrapper error added in imageResource.processActionSpec in Hugo when an image processing action (resize, crop, fit, fill, filter) fails. It wraps the underlying error (bad option spec, decode failure, unsupported format) with the action name and the image's source path so the user can identify which image and operation broke.","triggerScenarios":"Calling .Resize/.Crop/.Fit/.Fill/.Filter/.Process on an image resource in a template with an invalid option string (e.g. bad dimensions, unknown anchor, invalid quality), or on an image whose decode fails; processOptions returns an error and it is wrapped with the action and sourcePath.","commonSituations":"Typos in resize specs like `{{ $img.Resize \"x\" }}`, unsupported target formats, corrupt or truncated image files in assets/, EXIF/format edge cases, or processing an SVG/unsupported format as a raster image.","solutions":["Check the wrapped inner error and the reported source path to identify the failing image and action","Fix the option spec passed to Resize/Fit/Fill/Crop (e.g. \"600x400 webp q80\") per https://gohugo.io/content-management/image-processing/","Verify the source image opens in another tool; replace corrupt/truncated files","Ensure the image format is one Hugo can decode (jpg, png, gif, webp, tiff, bmp)"],"exampleFix":"// before\n{{ $img := resources.Get \"hero.jpg\" }}\n{{ $small := $img.Resize \"x\" }}\n// after\n{{ $img := resources.Get \"hero.jpg\" }}\n{{ $small := $img.Resize \"600x\" }}","handlingStrategy":"try-catch","validationCode":"{{ with resources.Get \"img.jpg\" }}{{ if in (slice \"image\") (index (split .MediaType.Type \"/\") 0) }}...{{ end }}{{ end }}","typeGuard":null,"tryCatchPattern":"{{ with try (.Resize \"800x\") }}{{ with .Err }}{{ warnf \"image op failed: %s\" . }}{{ else }}{{ .Value.RelPermalink }}{{ end }}{{ end }}","preventionTips":["Verify the resource is actually an image (MediaType main type == image) before calling Resize/Fit/Crop/Filter","Validate the operation spec string (dimensions, anchors, formats) against documented options","Use try/with .Err in templates so a single corrupt image doesn't fail the whole build","Test builds with the actual asset set in CI to catch corrupt or truncated images early"],"tags":["hugo","image-processing","templates"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}