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 1 outputs

What it means

reflectx.ToFunc0x1 adapts a Func to Func0x1 (0 inputs, 1 output) and panics unless the reflect type has exactly 0 inputs and 1 output. The panic message reports the actual function type, input count and output count.

Solutions

  1. Match the adapter to the signature: for (value, error) returns use a 0x2 adapter, for func(T) T use ToFunc1x1.
  2. Drop the error return or handle it inside the function body so the signature is func() T.
  3. Inspect fn.Type().NumIn()/NumOut() at runtime and choose the correct ToFuncNxx variant.

Example fix

// before
reflectx.ToFunc0x1(reflectx.MakeFunc(func() (int, error) { ... }))
// after
reflectx.ToFunc0x2(reflectx.MakeFunc(func() (int, error) { ... }))
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Calling ToFunc0x1 or MakeFunc0x1 with a func that has inputs (e.g. func(int) int) or the wrong number of returns (e.g. func() (T, error)).

Common situations: Trying to adapt a supplier that returns (value, error) — the error second return makes NumOut()==2 and trips the check; passing a mapper function expecting an element argument.

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/5092194dbed83ee1. Report an issue: GitHub.

Appendix: source

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

}

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

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

func (c *shimFunc0x1) Call0x1() any {
	ret := c.inner.Call([]any{})
	_ = ret
	return ret[0]
}

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

func MakeFunc0x1(fn any) Func0x1 {
	return ToFunc0x1(MakeFunc(fn))
}

type Func0x2 interface {
	Func
	Call0x2() (any, any)
}

type shimFunc0x2 struct {
	inner Func

View on GitHub (pinned to 12126d8942)