kataras/iris · error
bad value: function has invalid number of output arguments:
Error message
bad value: function has invalid number of output arguments: %v
What it means
Dependency functions may return at most two values: the dependency (optionally plus an error). Any function returning three or more values cannot be mapped to a single dependency and panics.
Source
Thrown at hero/dependency.go:302
}
// fallback to structure.
return fromStructValue(v.Call(nil)[0], dest)
}
if numOut == 0 {
panic("bad value: function has zero outputs")
}
if numOut == 2 && !isError(typ.Out(1)) {
panic("bad value: second output should be an error")
}
if numOut > 2 {
// - at least one output value
// - maximum of two output values
// - second output value should be a type of error.
panic(fmt.Sprintf("bad value: function has invalid number of output arguments: %v", numOut))
}
var handler DependencyHandler
firstIsContext := isContext(typ.In(0))
secondIsInput := numIn == 2 && typ.In(1) == inputTyp
onlyContext := (numIn == 1 && firstIsContext) || (numIn == 2 && firstIsContext && typ.IsVariadic())
if onlyContext || (firstIsContext && secondIsInput) {
handler = handlerFromFunc(v, typ)
}
if handler == nil {
return false
}
dest.DestType = typ.Out(0)
dest.Handle = handlerView on GitHub (pinned to 7bedaf55a0)
Solutions
- Reduce outputs to (T) or (T, error).
- Bundle multiple outputs into one struct: type Deps struct{ A A; B B } and return (Deps, error).
- Register a thin wrapper closure that collapses the multi-return: c.Register(func() (A, error) { a, b, err := f(); return a, err }).
Example fix
// before
func newClients() (*ClientA, *ClientB, error) { ... }
c.Register(newClients)
// after
type Clients struct { A *ClientA; B *ClientB }
func newClients() (*Clients, error) { ... }
c.Register(newClients) Defensive patterns
Strategy: validation
Validate before calling
func outCountOK(fn any) bool { n := reflect.TypeOf(fn).NumOut(); return n == 1 || n == 2 } Prevention
- Cap dependency funcs at (T) or (T, error).
- Bundle multi-results into one struct.
- Wrap multi-return libraries APIs in single-result closures.
When it happens
Trigger: Registering funcs like func() (A, B, error) or func(cfg) (A, B, C) via c.Register/NewDependency.
Common situations: Go idiom of multi-return factories used directly as a dependency; returning the dependency plus metrics/clients alongside error; gRPC-style (resp, err) wrapped further.
Related errors
- bad value: function has zero inputs: empty input function mu
- bad value: function has zero outputs
- bad value: second output should be an error
- api container: set dependency matcher: fn cannot be nil
- bindings: unresolved: no a func type: %#+v
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/7c445ed64742f866.
Report an issue: GitHub.