gohugoio/hugo · error

requires 1 or 2 arguments

Error message

requires 1 or 2 arguments

What it means

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.

Source

Thrown at tpl/images/images.go:134

// QR encodes the given text into a QR code using the specified options,
// returning an image resource.
func (ns *Namespace) QR(args ...any) (images.ImageResource, error) {
	const (
		qrDefaultErrorCorrectionLevel = "medium"
		qrDefaultScale                = 4
	)

	opts := struct {
		Level     string // error correction level; one of low, medium, quartile, or high
		Scale     int    // number of image pixels per QR code module
		TargetDir string // target directory relative to publishDir
	}{
		Level: qrDefaultErrorCorrectionLevel,
		Scale: qrDefaultScale,
	}

	if len(args) == 0 || len(args) > 2 {
		return nil, errors.New("requires 1 or 2 arguments")
	}

	text, err := cast.ToStringE(args[0])
	if err != nil {
		return nil, err
	}

	if text == "" {
		return nil, errors.New("cannot encode an empty string")
	}

	if len(args) == 2 {
		err := mapstructure.WeakDecode(args[1], &opts)
		if err != nil {
			return nil, err
		}
	}

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Pass exactly the text: `{{ images.QR "https://gohugo.io" }}`.
  2. Or pass text plus an options map: `{{ images.QR $text (dict "level" "high" "scale" 8) }}`.
  3. Consolidate all configuration into the single options dict.

Example fix

// before
{{ images.QR $text $opts "extra" }}
// after
{{ images.QR $text $opts }}
Defensive patterns

Strategy: validation

Validate before calling

{{ if and (ge (len $args) 1) (le (len $args) 2) }}
  {{ images.QR $args... }}
{{ end }}

Type guard

func validQRArity(n int) bool { return n == 1 || n == 2 }

Prevention

When it happens

Trigger: Calling `{{ images.QR }}` with no arguments, or `{{ images.QR $text $opts $extra }}` with three. The bounds are `[1, 2]`.

Common situations: A developer omits the text argument entirely (e.g. a broken partial passes nothing), or adds extra positional options beyond the single options map.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/44cf0ac310abeeed. Report an issue: GitHub.