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 2 outputs
What it means
reflectx.ToFunc6x2 wraps a reflectx.Func into a Func6x2 (6 inputs, 2 outputs). It panics with this message if the func's reflect.Type does not have exactly 6 inputs and 2 outputs, as the shim returns ret[0], ret[1].
Solutions
- Make the function take 6 inputs and return exactly 2 values.
- Select the matching ToFuncN x M variant for the real signature.
- Verify the fixed-arity type expected by the pipeline (e.g. Func6x2) is what the DoFn actually implements.
Example fix
// before
func fn(a A, b B, c C, d D, e E, f F) (T, U, V) { ... }
reflectx.ToFunc6x2(fn) // panics: 3 outputs
// after
func fn(a A, b B, c C, d D, e E, f F) (T, U) { ... }
reflectx.ToFunc6x2(fn) Defensive patterns
Strategy: validation
Validate before calling
fn := reflect.TypeOf(fnAny)
if fn.Kind() == reflect.Func && fn.NumIn() == 6 && fn.NumOut() == 2 {
_ = reflectx.ToFunc6x2(fnAny)
} Type guard
func isFunc6x2(f interface{}) bool {
t := reflect.TypeOf(f)
return t != nil && t.Kind() == reflect.Func && t.NumIn() == 6 && t.NumOut() == 2
} Try / catch
func safeToFunc6x2(c reflectx.Func) (f reflectx.Func6x2, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("ToFunc6x2 failed: %v", r)
}
}()
return reflectx.ToFunc6x2(c), nil
} Prevention
- Clarify whether two outputs are two emitted values or value+error and pick the helper accordingly.
- Synchronize signature changes with the NxM registration helper.
- Add reflection assertions near DoFn definitions.
- Avoid duplicating registration lines across pipeline builders.
When it happens
Trigger: Calling reflectx.ToFunc6x2(c) where c.Type().NumIn() != 6 or c.Type().NumOut() != 2 — e.g. emitting 1 or 3 values, or taking 5 inputs.
Common situations: FlatMap-style DoFns whose emission count changed during refactor; confusion between (value, error) and two-emitted-values conventions; wrong ToFunc helper selected for the DoFn's actual shape.
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
- failed to construct userfn
- Incompatible func type: got func
- Incompatible func type: got func
- Incompatible func type: got func
- Incompatible func type: got func
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/33fa77d5acb83cdc.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/util/reflectx/calls.go:1377
}
func (c *shimFunc6x2) Type() reflect.Type {
return c.inner.Type()
}
func (c *shimFunc6x2) Call(args []any) []any {
return c.inner.Call(args)
}
func (c *shimFunc6x2) Call6x2(arg0, arg1, arg2, arg3, arg4, arg5 any) (any, any) {
ret := c.inner.Call([]any{arg0, arg1, arg2, arg3, arg4, arg5})
_ = ret
return ret[0], ret[1]
}
func ToFunc6x2(c Func) Func6x2 {
if c.Type().NumIn() != 6 || c.Type().NumOut() != 2 {
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 6 inputs and 2 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
}
if sc, ok := c.(Func6x2); ok {
return sc
}
return &shimFunc6x2{inner: c}
}
func MakeFunc6x2(fn any) Func6x2 {
return ToFunc6x2(MakeFunc(fn))
}
type Func6x3 interface {
Func
Call6x3(any, any, any, any, any, any) (any, any, any)
}
type shimFunc6x3 struct {
inner FuncView on GitHub (pinned to 12126d8942)