kataras/iris · error

bad value: function has zero inputs: empty input function mu

Error message

bad value: function has zero inputs: empty input function must output a single value but got: length=%v, type[0]=%s

What it means

fromFunc validates zero-input functions: an empty function must return exactly one struct or interface value (the container falls back to treating its return as a struct dependency). If the returned type count or kind does not satisfy this, it panics.

Source

Thrown at hero/dependency.go:282

	dest.Handle = handler
	return true
}

func fromFunc(v reflect.Value, dest *Dependency) bool {
	if !isFunc(v) {
		return false
	}

	typ := v.Type()
	numIn := typ.NumIn()
	numOut := typ.NumOut()

	if numIn == 0 {
		// it's an empty function, that must return a structure.
		if numOut != 1 {
			firstOutType := indirectType(typ.Out(0))
			if firstOutType.Kind() != reflect.Struct && firstOutType.Kind() != reflect.Interface {
				panic(fmt.Sprintf("bad value: function has zero inputs: empty input function must output a single value but got: length=%v, type[0]=%s", numOut, firstOutType.String()))
			}
		}

		// 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

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Make a zero-input function return exactly one struct or interface: func() *MyStruct { ... }.
  2. If you need multiple outputs, use inputs+error signature instead: func(x X) (*Svc, error).
  3. Wrap primitives in a struct: func() Config { return Config{Host: ...} } instead of func() string.
  4. If it's an interface return, ensure the concrete implementation is also registerable/bindable.

Example fix

// before
func port() int { return 8080 } // panic: not struct/interface
// after
type Port int
func port() Port { return 8080 } // named struct-like type? use struct instead:
// or: func port() Config { return Config{Port: 8080} }
Defensive patterns

Strategy: validation

Validate before calling

func isValidZeroInputFunc(fn any) bool {
	t := reflect.TypeOf(fn)
	if t.NumIn() != 0 { return true } // not this error's case
	if t.NumOut() != 1 { return false }
	k := t.Out(0).Kind()
	return k == reflect.Struct || k == reflect.Interface
}

Try / catch

func() { defer func() { if r := recover(); r != nil { log.Fatalf("dependency func invalid: %v", r) } }()
	c.Register(fn) }()

Prevention

When it happens

Trigger: Registering func() (a, b) (multiple outputs) or func() someNonStructType (e.g. int, string, slice, map) through NewDependency/resolveDependency.

Common situations: Returning a primitive like func() string to provide a config value; forgetting that only struct/interface returns are valid for zero-input funcs; copy-pasting a multi-return factory func() (*Svc, error) into a zero-input position.

Related errors


AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30). Data as JSON: /api/errors/8eca21307a576b63. Report an issue: GitHub.