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 1 outputs
What it means
reflectx.ToFunc6x1 wraps a reflectx.Func into a Func6x1 (6 inputs, 1 output). It panics with this message when the func's reflect.Type has any other arity, because the shim returns ret[0] directly and would index out of range otherwise.
Solutions
- Adjust the function to 6 inputs and exactly 1 return value.
- Use ToFunc6x2 for a (T, error) style signature or ToFunc6x0 for void.
- Cross-check the expected signature in the Beam registration and fix the mismatched side.
Example fix
// before
func fn(a A, b B, c C, d D, e E, f F) (T, error) { ... }
reflectx.ToFunc6x1(fn) // panics: 2 outputs
// after
func fn(a A, b B, c C, d D, e E, f F) T { ... }
reflectx.ToFunc6x1(fn) Defensive patterns
Strategy: validation
Validate before calling
fn := reflect.TypeOf(fnAny)
if fn.Kind() == reflect.Func && fn.NumIn() == 6 && fn.NumOut() == 1 {
_ = reflectx.ToFunc6x1(fnAny)
} Type guard
func isFunc6x1(f interface{}) bool {
t := reflect.TypeOf(f)
return t != nil && t.Kind() == reflect.Func && t.NumIn() == 6 && t.NumOut() == 1
} Try / catch
func safeToFunc6x1(c reflectx.Func) (f reflectx.Func6x1, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("ToFunc6x1 failed: %v", r)
}
}()
return reflectx.ToFunc6x1(c), nil
} Prevention
- Treat (T, error) as 2 outputs; use the x2 helper or remove the error.
- Verify parameter count after adding context or timestamp parameters.
- Wrap-test all user functions in CI.
- Match helper names to signatures during code review.
When it happens
Trigger: Calling reflectx.ToFunc6x1(c) where c.Type().NumIn() != 6 or c.Type().NumOut() != 1 — e.g. a 6-input function returning (T, error) or nothing.
Common situations: Map-style DoFns with 6 params returning 2 values; registration drift after adding a context/timestamp parameter; choosing the wrong ToFunc helper when converting to a fixed-arity type.
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/f71633d201becf19.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/util/reflectx/calls.go:1336
}
func (c *shimFunc6x1) Type() reflect.Type {
return c.inner.Type()
}
func (c *shimFunc6x1) Call(args []any) []any {
return c.inner.Call(args)
}
func (c *shimFunc6x1) Call6x1(arg0, arg1, arg2, arg3, arg4, arg5 any) any {
ret := c.inner.Call([]any{arg0, arg1, arg2, arg3, arg4, arg5})
_ = ret
return ret[0]
}
func ToFunc6x1(c Func) Func6x1 {
if c.Type().NumIn() != 6 || c.Type().NumOut() != 1 {
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 6 inputs and 1 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
}
if sc, ok := c.(Func6x1); ok {
return sc
}
return &shimFunc6x1{inner: c}
}
func MakeFunc6x1(fn any) Func6x1 {
return ToFunc6x1(MakeFunc(fn))
}
type Func6x2 interface {
Func
Call6x2(any, any, any, any, any, any) (any, any)
}
type shimFunc6x2 struct {
inner FuncView on GitHub (pinned to 12126d8942)