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

What it means

reflectx.ToFunc8x3 adapts a Func into an 8-input/3-output function and panics when NumIn != 8 or NumOut != 3, since the shim returns exactly ret[0], ret[1], ret[2]. The panic message states the got and want arity plus the offending func type. It fires at pipeline-construction time.

Solutions

  1. Adjust the function to exactly 8 inputs and 3 outputs
  2. Pick the converter matching the real arity (ToFunc8x2, ToFunc7x3, etc.)
  3. Fix the target FuncNxM type at the registration call site
  4. Add an arity assertion/test before building the pipeline

Example fix

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

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Calling ToFunc8x3 (or MakeFunc8x3) with a Func whose signature has any other shape, e.g. an 8-in/2-out function or a 9-in/3-out function.

Common situations: Three-output DoFns where an output or error return was added/removed; extra emitter parameter added (7<->8 inputs) without updating the conversion; wrong slot chosen in hand-written or generated registration code.

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

Appendix: source

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

}

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

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

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

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

func MakeFunc8x3(fn any) Func8x3 {
	return ToFunc8x3(MakeFunc(fn))
}

type Func8x4 interface {
	Func
	Call8x4(any, any, any, any, any, any, any, any) (any, any, any, any)
}

type shimFunc8x4 struct {
	inner Func

View on GitHub (pinned to 12126d8942)