{"record":{"id":"44cf0ac310abeeed","repo":"gohugoio/hugo","slug":"requires-1-or-2-arguments","errorCode":null,"errorMessage":"requires 1 or 2 arguments","messagePattern":"requires 1 or 2 arguments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/images/images.go","lineNumber":134,"sourceCode":"// 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) {\n\tconst (\n\t\tqrDefaultErrorCorrectionLevel = \"medium\"\n\t\tqrDefaultScale                = 4\n\t)\n\n\topts := struct {\n\t\tLevel     string // error correction level; one of low, medium, quartile, or high\n\t\tScale     int    // number of image pixels per QR code module\n\t\tTargetDir string // target directory relative to publishDir\n\t}{\n\t\tLevel: qrDefaultErrorCorrectionLevel,\n\t\tScale: qrDefaultScale,\n\t}\n\n\tif len(args) == 0 || len(args) > 2 {\n\t\treturn nil, errors.New(\"requires 1 or 2 arguments\")\n\t}\n\n\ttext, err := cast.ToStringE(args[0])\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif text == \"\" {\n\t\treturn nil, errors.New(\"cannot encode an empty string\")\n\t}\n\n\tif len(args) == 2 {\n\t\terr := mapstructure.WeakDecode(args[1], &opts)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/images/images.go#L116-L152","documentation":"The `images.QR` function encodes text into a QR code image. It accepts either one argument (the text) or two (text + options map). The arity check at images.go:133–134 rejects zero arguments and three or more.","triggerScenarios":"Calling `{{ images.QR }}` with no arguments, or `{{ images.QR $text $opts $extra }}` with three. The bounds are `[1, 2]`.","commonSituations":"A developer omits the text argument entirely (e.g. a broken partial passes nothing), or adds extra positional options beyond the single options map.","solutions":["Pass exactly the text: `{{ images.QR \"https://gohugo.io\" }}`.","Or pass text plus an options map: `{{ images.QR $text (dict \"level\" \"high\" \"scale\" 8) }}`.","Consolidate all configuration into the single options dict."],"exampleFix":"// before\n{{ images.QR $text $opts \"extra\" }}\n// after\n{{ images.QR $text $opts }}","handlingStrategy":"validation","validationCode":"{{ if and (ge (len $args) 1) (le (len $args) 2) }}\n  {{ images.QR $args... }}\n{{ end }}","typeGuard":"func validQRArity(n int) bool { return n == 1 || n == 2 }","tryCatchPattern":null,"preventionTips":["Pass exactly one text argument or text plus one options map.","Consolidate configuration into the options dict.","Avoid positional extras."],"tags":["hugo","template","images","qr","arity"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}