{"record":{"id":"b83302fd479b54e2","repo":"gohugoio/hugo","slug":"must-provide-an-image-and-one-or-more-filters","errorCode":null,"errorMessage":"must provide an image and one or more filters","messagePattern":"must provide an image and one or more filters","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/images/images.go","lineNumber":100,"sourceCode":"\treturn ns.cache.GetOrCreate(filename, func() (image.Config, error) {\n\t\tf, err := ns.readFileFs.Open(filename)\n\t\tif err != nil {\n\t\t\treturn image.Config{}, err\n\t\t}\n\t\tdefer f.Close()\n\n\t\text := filepath.Ext(filename)\n\t\tformat, _ := images.ImageFormatFromExt(ext)\n\n\t\tconfig, _, err := ns.deps.ResourceSpec.Imaging.Codec.DecodeConfig(format, f)\n\t\treturn config, err\n\t})\n}\n\n// Filter applies the given filters to the image given as the last element in args.\nfunc (ns *Namespace) Filter(args ...any) (images.ImageResource, error) {\n\tif len(args) < 2 {\n\t\treturn nil, errors.New(\"must provide an image and one or more filters\")\n\t}\n\n\timg := args[len(args)-1].(images.ImageResource)\n\tfiltersv := args[:len(args)-1]\n\n\treturn img.Filter(filtersv...)\n}\n\nvar qrErrorCorrectionLevels = map[string]qr.Level{\n\t\"low\":      qr.L,\n\t\"medium\":   qr.M,\n\t\"quartile\": qr.Q,\n\t\"high\":     qr.H,\n}\n\n// QR encodes the given text into a QR code using the specified options,\n// returning an image resource.\nfunc (ns *Namespace) QR(args ...any) (images.ImageResource, error) {","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/images/images.go#L82-L118","documentation":"The `images.Filter` function applies one or more image filters to an image resource. The image resource must be the last argument and at least one filter must precede it. The check at images.go:99–100 requires `len(args) >= 2` (at least one filter + the image).","triggerScenarios":"Calling `{{ (images.Filter $filter) }}` (only a filter, no image), `{{ (images.Filter $img) }}` (only an image, no filter), or `{{ images.Filter }}` (no args).","commonSituations":"A developer places the image first and the filter second (reversed order), or passes only the filter expecting it to apply to the current page's image. The last argument must be the image.","solutions":["Ensure the last argument is the image resource and at least one filter precedes it: `{{ (images.Filter $filter1 $filter2 $image) }}`.","Check argument order — image comes last, not first.","Verify the image variable is a valid `images.ImageResource`."],"exampleFix":"// before\n{{ (images.Filter $image $filter) }}\n// after\n{{ (images.Filter $filter $image) }}","handlingStrategy":"validation","validationCode":"// Ensure image is last and at least one filter precedes it\n{{ if and (ge (len $args) 2) (isImageResource (index $args (sub (len $args) 1))) }}\n  {{ (images.Filter $args...) }}\n{{ end }}","typeGuard":"func validFilterArgs(args []any) bool {\n    if len(args) < 2 { return false }\n    _, ok := args[len(args)-1].(images.ImageResource)\n    return ok\n}","tryCatchPattern":null,"preventionTips":["Place the image resource as the last argument.","Ensure at least one filter precedes the image.","Verify the image variable is a valid ImageResource."],"tags":["hugo","template","images","filter","arity"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}