gohugoio/hugo · error
%s is a method of type %s but returns no output
Error message
%s is a method of type %s but returns no output
What it means
`evaluateSubElem` (where.go:344-345) requires a method used as a `where` key to produce a value it can compare against the match argument. If `mt.Type.NumOut() == 0` the method returns nothing, so there is no value to filter on, and Hugo rejects it.
Source
Thrown at tpl/collections/where.go:345
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 be
// a nil value
if isNil {View on GitHub (pinned to 52c9bd7908)
Solutions
- Filter on a real value: a field or a method that returns the post-reset state.
- Expose an exported field carrying the boolean/value you actually want to match.
- If you need the side effect, perform it in a `range` before filtering, not as a where key.
Example fix
// before
{{ where $items "Reset" "==" true }} {{/* Reset() returns nothing */}}
// after
{{ where $items "NeedsReset" "==" true }} {{/* NeedsReset() bool */}} Defensive patterns
Strategy: validation
Validate before calling
// Go-side: only allow methods that return at least one value mt, ok := reflect.TypeOf(item).MethodByName(name) ok = ok && mt.Type.NumOut() >= 1
Prevention
- Reserve `where` keys for value-returning query methods, not mutators.
- Name command-style methods (Reset, Save, Load) distinctly from query methods.
- Document which methods are template-safe.
When it happens
Trigger: `{{ where $items "Reset" "==" true }}` against a method `func (i *Item) Reset()` that performs a side effect with no return value.
Common situations: Treating a command/mutator method as a query; copy-pasting a method name that happens to be a void action; migrating from a field to a setter method.
Related errors
- %s is a method of type %s but requires more than %d paramete
- %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/aefb8536d1a39174.
Report an issue: GitHub.