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 3 outputs
What it means
reflectx.ToFunc5x3 wraps a reflectx.Func into a Func5x3 (5 inputs, 3 outputs). It panics with this message when the func's reflect.Type has any arity other than 5 inputs and 3 outputs. The shim needs the exact arity to return ret[0], ret[1], ret[2].
Solutions
- Align the function to exactly 5 inputs and 3 return values.
- Use the ToFunc variant matching the real output count (ToFunc5x2, ToFunc5x4, etc.).
- Audit the ProcessElement signature against the fixed-arity type used at registration time.
Example fix
// before
func fn(a A, b B, c C, d D, e E) (T, U) { ... }
reflectx.ToFunc5x3(fn) // panics: 2 outputs
// after
func fn(a A, b B, c C, d D, e E) (T, U, V) { ... }
reflectx.ToFunc5x3(fn) Defensive patterns
Strategy: validation
Validate before calling
fn := reflect.TypeOf(fnAny)
if fn.Kind() == reflect.Func && fn.NumIn() == 5 && fn.NumOut() == 3 {
_ = reflectx.ToFunc5x3(fnAny)
} Type guard
func isFunc5x3(f interface{}) bool {
t := reflect.TypeOf(f)
return t != nil && t.Kind() == reflect.Func && t.NumIn() == 5 && t.NumOut() == 3
} Try / catch
func safeToFunc5x3(c reflectx.Func) (f reflectx.Func5x3, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("ToFunc5x3 failed: %v", r)
}
}()
return reflectx.ToFunc5x3(c), nil
} Prevention
- For multi-output functions, verify the emitted-value count matches the registered arity exactly.
- Prefer generic registration APIs over fixed-arity helpers when signatures are in flux.
- Add reflection-based assertions near DoFn definitions.
- Review signature diffs in PRs for input/output count changes.
When it happens
Trigger: Calling reflectx.ToFunc5x3(c) where c.Type().NumIn() != 5 or c.Type().NumOut() != 3 — e.g. a function emitting 2 or 4 values, or taking 4 or 6 inputs.
Common situations: DoFns emitting multiple outputs where the emitted-value count was changed (added/dropped a return) without updating the registration; mixing up (value..., error) conventions with pure multi-emission signatures.
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/33acd3a99c23ee05.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/util/reflectx/calls.go:1213
}
func (c *shimFunc5x3) Type() reflect.Type {
return c.inner.Type()
}
func (c *shimFunc5x3) Call(args []any) []any {
return c.inner.Call(args)
}
func (c *shimFunc5x3) Call5x3(arg0, arg1, arg2, arg3, arg4 any) (any, any, any) {
ret := c.inner.Call([]any{arg0, arg1, arg2, arg3, arg4})
_ = ret
return ret[0], ret[1], ret[2]
}
func ToFunc5x3(c Func) Func5x3 {
if c.Type().NumIn() != 5 || c.Type().NumOut() != 3 {
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 5 inputs and 3 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
}
if sc, ok := c.(Func5x3); ok {
return sc
}
return &shimFunc5x3{inner: c}
}
func MakeFunc5x3(fn any) Func5x3 {
return ToFunc5x3(MakeFunc(fn))
}
type Func5x4 interface {
Func
Call5x4(any, any, any, any, any) (any, any, any, any)
}
type shimFunc5x4 struct {
inner FuncView on GitHub (pinned to 12126d8942)