gohugoio/hugo · error
wrong number of args for %s: got %d want %d
Error message
wrong number of args for %s: got %d want %d
What it means
Raised by the `call` action for a non-variadic function when the argument count does not equal `numIn` (funcs.go:333-334). Non-variadic funcs require an exact arity match. Format: `name got want`.
Source
Thrown at tpl/internal/go_templates/texttemplate/funcs.go:334
}
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 {
return reflect.Value{}, fmt.Errorf("arg %d: %w", i, err)
}
}
return safeCall(fn, argv)
}View on GitHub (pinned to 52c9bd7908)
Solutions
- Match the exact argument count declared in Go.
- Check the FuncMap/method signature and align the call site.
- Use a wrapper with optional defaults if the call sites vary.
Example fix
// before
{{call .Add 1 2 3}} // func(int, int) int
// after
{{call .Add 1 2}} Defensive patterns
Strategy: validation
Validate before calling
// Match exact arity for non-variadic funcs:
// {{call .Add 1 2}} // func(int, int) int
// Audit call sites when refactoring a func's parameter list. Prevention
- Keep call-site arg counts aligned with declared signatures.
- When changing a func signature, search templates for callers.
- Use wrapper funcs with defaults to absorb signature changes.
When it happens
Trigger: `{{call .Fn 1 2}}` on `func(int) int`; calling a method with the wrong number of args; refactoring a helper to add/remove a parameter without updating templates.
Common situations: Signature drift after a refactor; template written against an older version of the func; passing a pipeline arg that adds an unexpected operand.
Related errors
- call of nil
- non-function %s of type %s
- wrong number of args for %s: got %d want at least %d
- arg %d: %w
- %v
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/71314d131957e592.
Report an issue: GitHub.