apache/beam · error

Incompatible func type: got func

Error message

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

What it means

reflectx.ToFunc6x3 wraps a reflectx.Func into a Func6x3 (6 inputs, 3 outputs). It panics with this message unless the func's reflect.Type has exactly 6 inputs and 3 outputs, since the shim unpacks ret[0], ret[1], ret[2] positionally.

Solutions

  1. Align the function to exactly 6 inputs and 3 return values.
  2. Use the ToFunc helper matching the actual arity (ToFunc6x2, ToFunc6x4, etc.).
  3. Inspect the ProcessElement signature and the fixed-arity type used at registration; fix whichever is inconsistent.

Example fix

// before
func fn(a A, b B, c C, d D, e E, f F) (T, U) { ... }
reflectx.ToFunc6x3(fn) // panics: 2 outputs

// after
func fn(a A, b B, c C, d D, e E, f F) (T, U, V) { ... }
reflectx.ToFunc6x3(fn)
Defensive patterns

Strategy: validation

Validate before calling

fn := reflect.TypeOf(fnAny)
if fn.Kind() == reflect.Func && fn.NumIn() == 6 && fn.NumOut() == 3 {
    _ = reflectx.ToFunc6x3(fnAny)
}

Type guard

func isFunc6x3(f interface{}) bool {
    t := reflect.TypeOf(f)
    return t != nil && t.Kind() == reflect.Func && t.NumIn() == 6 && t.NumOut() == 3
}

Try / catch

func safeToFunc6x3(c reflectx.Func) (f reflectx.Func6x3, err error) {
    defer func() {
        if r := recover(); r != nil {
            err = fmt.Errorf("ToFunc6x3 failed: %v", r)
        }
    }()
    return reflectx.ToFunc6x3(c), nil
}

Prevention

When it happens

Trigger: Calling reflectx.ToFunc6x3(c) where c.Type().NumIn() != 6 or c.Type().NumOut() != 3 — e.g. a multi-output DoFn emitting 2 or 4 values, or one with the wrong input parameter count.

Common situations: Fan-out DoFns whose output tuple size drifted from the registered arity; mixing emit-style signatures with return-style ones; copy-paste of a registration line without updating the NxM helper.

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

Appendix: source

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

}

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

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

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

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

func MakeFunc6x3(fn any) Func6x3 {
	return ToFunc6x3(MakeFunc(fn))
}

type Func6x4 interface {
	Func
	Call6x4(any, any, any, any, any, any) (any, any, any, any)
}

type shimFunc6x4 struct {
	inner Func

View on GitHub (pinned to 12126d8942)