apache/beam · error

Incompatible func type: got func %v with %v inputs and %v ou

Error message

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

What it means

reflectx.ToFunc7x2 wraps a Func as a 7-input/2-output function and panics if the underlying signature does not match exactly. Shims like shimFunc7x2 unpack ret[0], ret[1], so any other output count cannot be supported. This is a construction-time programmer-error panic.

Source

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

}

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

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

func (c *shimFunc7x2) Call7x2(arg0, arg1, arg2, arg3, arg4, arg5, arg6 any) (any, any) {
	ret := c.inner.Call([]any{arg0, arg1, arg2, arg3, arg4, arg5, arg6})
	_ = ret
	return ret[0], ret[1]
}

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

func MakeFunc7x2(fn any) Func7x2 {
	return ToFunc7x2(MakeFunc(fn))
}

type Func7x3 interface {
	Func
	Call7x3(any, any, any, any, any, any, any) (any, any, any)
}

type shimFunc7x3 struct {
	inner Func

View on GitHub (pinned to 12126d8942)

Solutions

  1. Make the function take exactly 7 parameters and return exactly 2 values
  2. Use the correct NxM converter matching the real signature (e.g. ToFunc7x1, ToFunc6x2)
  3. Update call sites after signature refactors to the newly matching Func type
  4. Pre-validate with c.Type().NumIn()/NumOut() before converting in dynamic code

Example fix

// before
func(a, b, c, d, e, f2 any) (any, error) { ... } // 6 inputs
reflectx.ToFunc7x2(reflectx.NewFunc(fn)) // panics
// after
func(a, b, c, d, e, f2, g any) (any, error) { ... } // 7 inputs, 2 outputs
reflectx.ToFunc7x2(reflectx.NewFunc(fn)) // OK
Defensive patterns

Strategy: validation

Validate before calling

t := f.Type()
if t.NumIn() != 7 || t.NumOut() != 2 {
    return fmt.Errorf("ToFunc7x2 needs 7 in / 2 out, got %d in / %d out (%v)", t.NumIn(), t.NumOut(), t)
}

Type guard

func isFunc7x2(f reflectx.Func) bool {
    t := f.Type()
    return t.NumIn() == 7 && t.NumOut() == 2
}

Try / catch

func safeToFunc7x2(f reflectx.Func) (fn reflectx.Func7x2, err error) {
    defer func() {
        if r := recover(); r != nil {
            err = fmt.Errorf("conversion failed: %v", r)
        }
    }()
    fn = reflectx.ToFunc7x2(f)
    return
}

Prevention

When it happens

Trigger: Calling ToFunc7x2 (or MakeFunc7x2) with a Func having inputs != 7 or outputs != 2, e.g. a 7-in/1-out function or a 6-in/2-out function.

Common situations: Functions dropping the added error return (2->1 outputs) without changing the registration; DoFn signatures evolving to add a context param (6->7 inputs) while keeping the old converter; template-copied registration calls.

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/5d36fee4273d89ff. Report an issue: GitHub.