apache/beam · error
Incompatible func type: got func
Error message
Incompatible func type: got func %v with %v inputs and %v outputs, want 5 inputs and 4 outputs
What it means
reflectx.ToFunc5x4 wraps a reflectx.Func into a Func5x4 (5 inputs, 4 outputs). It panics with this message unless the func's reflect.Type has exactly 5 inputs and 4 outputs, because the shim unpacks four return values positionally.
Solutions
- Make the function take 5 inputs and return exactly 4 values.
- Choose the ToFuncN x M wrapper matching the actual signature.
- Confirm the Beam registration (beam.ParDo / TryParDo) expects a 5x4 signature and adjust whichever side is wrong.
Example fix
// before
func fn(a A, b B, c C, d D, e E) (T, U, V) { ... }
reflectx.ToFunc5x4(fn) // panics: 3 outputs
// after
func fn(a A, b B, c C, d D, e E) (Q, T, U, V) { ... }
reflectx.ToFunc5x4(fn) Defensive patterns
Strategy: validation
Validate before calling
fn := reflect.TypeOf(fnAny)
if fn.Kind() == reflect.Func && fn.NumIn() == 5 && fn.NumOut() == 4 {
_ = reflectx.ToFunc5x4(fnAny)
} Type guard
func isFunc5x4(f interface{}) bool {
t := reflect.TypeOf(f)
return t != nil && t.Kind() == reflect.Func && t.NumIn() == 5 && t.NumOut() == 4
} Try / catch
func safeToFunc5x4(c reflectx.Func) (f reflectx.Func5x4, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("ToFunc5x4 failed: %v", r)
}
}()
return reflectx.ToFunc5x4(c), nil
} Prevention
- Document each multi-output DoFn's exact signature next to its definition.
- Run a pre-submission check that wraps all functions with their intended ToFunc helpers.
- Keep emit-count and helper arity in sync during refactors.
- Use DoFn structs to let Beam infer arity instead of hand-picking helpers.
When it happens
Trigger: Calling reflectx.ToFunc5x4(c) where c.Type().NumIn() != 5 or c.Type().NumOut() != 4 — e.g. a multi-output DoFn emitting 3 values plus error (4 outputs but intended differently) or 4 values from the wrong input count.
Common situations: Complex fan-out DoFns whose output tuple grew/shrank during development; registering with the wrong fixed-arity wrapper; Go reflection surface mismatch after switching between func and DoFn struct styles.
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/491fb0cabcb69fac.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/util/reflectx/calls.go:1254
}
func (c *shimFunc5x4) Type() reflect.Type {
return c.inner.Type()
}
func (c *shimFunc5x4) Call(args []any) []any {
return c.inner.Call(args)
}
func (c *shimFunc5x4) Call5x4(arg0, arg1, arg2, arg3, arg4 any) (any, any, any, any) {
ret := c.inner.Call([]any{arg0, arg1, arg2, arg3, arg4})
_ = ret
return ret[0], ret[1], ret[2], ret[3]
}
func ToFunc5x4(c Func) Func5x4 {
if c.Type().NumIn() != 5 || c.Type().NumOut() != 4 {
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 5 inputs and 4 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
}
if sc, ok := c.(Func5x4); ok {
return sc
}
return &shimFunc5x4{inner: c}
}
func MakeFunc5x4(fn any) Func5x4 {
return ToFunc5x4(MakeFunc(fn))
}
type Func6x0 interface {
Func
Call6x0(any, any, any, any, any, any)
}
type shimFunc6x0 struct {
inner FuncView on GitHub (pinned to 12126d8942)