apache/beam · error

Incompatible func type: got func

Error message

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

What it means

reflectx.ToFunc8x2 converts a Func to an 8-input/2-output typed function and panics if the arity differs. The shim returns ret[0], ret[1], which cannot represent any other output count. This is a deterministic construction-time panic for signature mismatches.

Solutions

  1. Make the function take exactly 8 parameters and return exactly 2 values
  2. Use the converter matching the true signature (ToFunc8x1, ToFunc7x2, etc.)
  3. Update registrations after any signature refactor to the newly matching Func type
  4. Pre-check c.Type().NumIn()/NumOut() where functions are chosen dynamically

Example fix

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

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Calling ToFunc8x2 (or MakeFunc8x2) with a Func of inputs != 8 or outputs != 2, e.g. an 8-in/1-out or 7-in/2-out function.

Common situations: Two-output DoFns refactored to return an error (1<->2 outputs) without re-picking the converter; adding/removing an input parameter (7<->8); generated-code arity drift between Beam SDK versions.

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

Appendix: source

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

}

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

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

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

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

func MakeFunc8x2(fn any) Func8x2 {
	return ToFunc8x2(MakeFunc(fn))
}

type Func8x3 interface {
	Func
	Call8x3(any, any, any, any, any, any, any, any) (any, any, any)
}

type shimFunc8x3 struct {
	inner Func

View on GitHub (pinned to 12126d8942)