gohugoio/hugo · error
%s is a method of type %s but requires more than %d paramete
Error message
%s is a method of type %s but requires more than %d parameter
What it means
`evaluateSubElem` (where.go:342-343) will only call a method via reflect if it takes no arguments beyond the receiver, optionally followed by a single `context.Context` as the second parameter (`maxNumIn` is 1, bumped to 2 for context at line 334). If `mt.Type.NumIn()` exceeds `maxNumIn`, the method cannot be invoked by `where` and this error is returned, reporting the allowed count.
Source
Thrown at tpl/collections/where.go:343
objPtr = objPtr.Addr()
}
mt := hreflect.GetMethodByNameForType(objPtr.Type(), elemName)
if mt.Func.IsValid() {
// Receiver is the first argument.
args := []reflect.Value{objPtr}
num := mt.Type.NumIn()
maxNumIn := 1
if num > 1 && hreflect.IsContextType(mt.Type.In(1)) {
args = append(args, ctx)
maxNumIn = 2
}
switch {
case mt.PkgPath != "":
return zero, fmt.Errorf("%s is an unexported method of type %s", elemName, typ)
case mt.Type.NumIn() > maxNumIn:
return zero, fmt.Errorf("%s is a method of type %s but requires more than %d parameter", elemName, typ, maxNumIn)
case mt.Type.NumOut() == 0:
return zero, fmt.Errorf("%s is a method of type %s but returns no output", elemName, typ)
case mt.Type.NumOut() > 2:
return zero, fmt.Errorf("%s is a method of type %s but returns more than 2 outputs", elemName, typ)
case mt.Type.NumOut() == 1 && mt.Type.Out(0).Implements(errorType):
return zero, fmt.Errorf("%s is a method of type %s but only returns an error type", elemName, typ)
case mt.Type.NumOut() == 2 && !mt.Type.Out(1).Implements(errorType):
return zero, fmt.Errorf("%s is a method of type %s returning two values but the second value is not an error type", elemName, typ)
}
res := mt.Func.Call(args)
if len(res) == 2 && !res[1].IsNil() {
return zero, fmt.Errorf("error at calling a method %s of type %s: %s", elemName, typ, res[1].Interface().(error))
}
return res[0], nil
}
// elemName isn't a method so next start to check whether it is
// a struct field or a map value. In both cases, it mustn't beView on GitHub (pinned to 52c9bd7908)
Solutions
- Switch the where key to a zero-arg method or a struct field that already holds the value.
- Refactor the element type to expose `func (t) Name(ctx ...context.Context) (T, error)` so it fits the 0-or-context-arg contract.
- Pre-compute the value into a field before building the collection.
Example fix
// before
{{ where $users "FullName" "==" "Bob" }} {{/* FullName(first, last) */}}
// after
{{ where $users "DisplayName" "==" "Bob" }} {{/* DisplayName() string */}} Defensive patterns
Strategy: validation
Validate before calling
// Go-side guard before exposing the collection to templates: // ensure the method signature is func() (T[, error]) or func(context.Context) (T[, error]) mt, ok := reflect.TypeOf(item).MethodByName(name) ok = ok && mt.Type.NumIn() <= 2 && (mt.Type.NumIn() == 1 || isContext(mt.Type.In(1)))
Prevention
- Design template-callable methods as zero-arg (optionally context) returning one value or (value, error).
- Run a unit test that reflect-checks each model method used in templates.
- Prefer fields over parameterized methods for `where` keys.
When it happens
Trigger: `{{ where $users "FullName" "==" "Bob" }}` against `func (u User) FullName(first, last string) string`. Any method whose signature needs caller-supplied arguments other than an optional leading context.
Common situations: Author assumes `where` can pass the match value into a finder method; a method was widened to take options and broke a previously-working template; using a builder-style method that takes config.
Related errors
- %s is a method of type %s but returns no output
- %s is a method of type %s but returns more than 2 outputs
- %s is a method of type %s but only returns an error type
- %s is a method of type %s returning two values but the secon
- %s is an unexported method of type %s
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/61e3c019e37ea16b.
Report an issue: GitHub.