apache/beam · error

Incompatible func type: got func

Error message

Incompatible func type: got func %v with %v inputs and %v outputs, want 0 inputs and 0 outputs

What it means

reflectx.ToFunc0x0 adapts a generic reflectx.Func to a Func0x0 (no inputs, no outputs) and panics if the underlying reflect function type does not have exactly 0 inputs and 0 outputs. The message includes the actual func type and its input/output counts.

Solutions

  1. Use the ToFunc/MakeFunc variant matching the real arity, e.g. ToFunc1x1 for func(T) T or ToFunc0x1 for func() T.
  2. Change the function to genuinely take no inputs and return nothing.
  3. If arity is dynamic, check fn.Type().NumIn()/NumOut() and dispatch to the right adapter before calling.

Example fix

// before
reflectx.ToFunc0x0(reflectx.MakeFunc(func(ctx context.Context) error { ... }))
// after
reflectx.ToFunc1x1(reflectx.MakeFunc(fn)) // or make fn truly func(){}
Defensive patterns

Strategy: validation

Validate before calling

func isFunc0x0(fn reflectx.Func) bool {
    return fn.Type().NumIn() == 0 && fn.Type().NumOut() == 0
}

Type guard

func asFunc0x0(fn reflectx.Func) (reflectx.Func0x0, bool) {
    if f, ok := fn.(reflectx.Func0x0); ok { return f, true }
    return nil, false
}

Try / catch

func safeToFunc0x0(fn reflectx.Func) (f reflectx.Func0x0, err error) {
    defer func() {
        if r := recover(); r != nil { err = fmt.Errorf("ToFunc0x0: %v", r) }
    }()
    return reflectx.ToFunc0x0(fn), nil
}

Prevention

When it happens

Trigger: Calling ToFunc0x0 or MakeFunc0x0 with a Func whose reflect type has any inputs or any outputs, e.g. a func(int) or func() error.

Common situations: Wrapping a DoFn-style method that returns an error or takes a context into a zero-arity shim; auto-registering functions by reflection where arity was not checked first.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/cb758e178e172947. Report an issue: GitHub.

Appendix: source

Thrown at sdks/go/pkg/beam/core/util/reflectx/calls.go:65

}

func (c *shimFunc0x0) Type() reflect.Type {
	return c.inner.Type()
}

func (c *shimFunc0x0) Call(args []any) []any {
	return c.inner.Call(args)
}

func (c *shimFunc0x0) Call0x0() {
	ret := c.inner.Call([]any{})
	_ = ret
	return
}

func ToFunc0x0(c Func) Func0x0 {
	if c.Type().NumIn() != 0 || c.Type().NumOut() != 0 {
		panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 0 inputs and 0 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
	}
	if sc, ok := c.(Func0x0); ok {
		return sc
	}
	return &shimFunc0x0{inner: c}
}

func MakeFunc0x0(fn any) Func0x0 {
	return ToFunc0x0(MakeFunc(fn))
}

type Func0x1 interface {
	Func
	Call0x1() any
}

type shimFunc0x1 struct {
	inner Func

View on GitHub (pinned to 12126d8942)