gohugoio/hugo · error

wrong number of args for %s: got %d want at least %d

Error message

wrong number of args for %s: got %d want at least %d

What it means

Raised by the `call` action when invoking a variadic function with fewer than `numIn-1` arguments (funcs.go:327-329). A variadic `func(a string, fs ...int)` needs at least one positional arg (the variadic may be empty, but fixed params must be present). Format: `name got wantAtLeast`.

Source

Thrown at tpl/internal/go_templates/texttemplate/funcs.go:329

// The function must return 1 result, or 2 results, the second of which is an error.
func call(name string, fn reflect.Value, args ...reflect.Value) (reflect.Value, error) {
	fn = indirectInterface(fn)
	if !fn.IsValid() {
		return reflect.Value{}, fmt.Errorf("call of nil")
	}
	typ := fn.Type()
	if typ.Kind() != reflect.Func {
		return reflect.Value{}, fmt.Errorf("non-function %s of type %s", name, typ)
	}

	if err := goodFunc(name, typ); err != nil {
		return reflect.Value{}, err
	}
	numIn := typ.NumIn()
	var dddType reflect.Type
	if typ.IsVariadic() {
		if len(args) < numIn-1 {
			return reflect.Value{}, fmt.Errorf("wrong number of args for %s: got %d want at least %d", name, len(args), numIn-1)
		}
		dddType = typ.In(numIn - 1).Elem()
	} else {
		if len(args) != numIn {
			return reflect.Value{}, fmt.Errorf("wrong number of args for %s: got %d want %d", name, len(args), numIn)
		}
	}
	argv := make([]reflect.Value, len(args))
	for i, arg := range args {
		arg = indirectInterface(arg)
		// Compute the expected type. Clumsy because of variadics.
		argType := dddType
		if !typ.IsVariadic() || i < numIn-1 {
			argType = typ.In(i)
		}

		var err error
		if argv[i], err = prepareArg(arg, argType); err != nil {

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Supply at least `numIn-1` args: pass the required positional parameters.
  2. Update the FuncMap entry or the call site to match the new signature.
  3. Add a default in a thin wrapper func so callers can omit it.

Example fix

// before
{{myJoin}}            // func(sep string, parts ...string)

// after
{{myJoin ","}}
Defensive patterns

Strategy: validation

Validate before calling

// Pass at least numIn-1 args (fixed params) for variadic funcs:
//   {{myJoin "," "a" "b"}}   // func(sep string, parts ...string)
// When unsure, check the func signature in Go.

Prevention

When it happens

Trigger: `{{call .VariadicFn}}` with no args when the function has a required leading parameter; `{{partial}}` wrappers that drop a required arg before forwarding to a variadic builtin.

Common situations: Registering a custom variadic template func and forgetting that the non-variadic params are mandatory; version bumps adding a required param to an existing variadic helper.

Related errors


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