apache/beam · error
Incompatible func type: got func %v with %v inputs and %v ou
Error message
Incompatible func type: got func %v with %v inputs and %v outputs, want 3 inputs and 3 outputs
What it means
reflectx.ToFunc3x3 converts a generic Func to a strongly-typed Func3x3 (3 inputs, 3 outputs). It panics when the underlying reflect.Type's NumIn() is not 3 or NumOut() is not 3. Beam throws this at conversion time so that the reflection shim's fixed return count matches the wrapped function; a mismatch would otherwise surface as an index-out-of-range or wrong-value bug deep inside the runner.
Source
Thrown at sdks/go/pkg/beam/core/util/reflectx/calls.go:803
}
func (c *shimFunc3x3) Type() reflect.Type {
return c.inner.Type()
}
func (c *shimFunc3x3) Call(args []any) []any {
return c.inner.Call(args)
}
func (c *shimFunc3x3) Call3x3(arg0, arg1, arg2 any) (any, any, any) {
ret := c.inner.Call([]any{arg0, arg1, arg2})
_ = ret
return ret[0], ret[1], ret[2]
}
func ToFunc3x3(c Func) Func3x3 {
if c.Type().NumIn() != 3 || c.Type().NumOut() != 3 {
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 3 inputs and 3 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
}
if sc, ok := c.(Func3x3); ok {
return sc
}
return &shimFunc3x3{inner: c}
}
func MakeFunc3x3(fn any) Func3x3 {
return ToFunc3x3(MakeFunc(fn))
}
type Func3x4 interface {
Func
Call3x4(any, any, any) (any, any, any, any)
}
type shimFunc3x4 struct {
inner FuncView on GitHub (pinned to 12126d8942)
Solutions
- Make the function take exactly 3 parameters and return exactly 3 values.
- Use the converter matching the real arity: ToFunc3x2 or ToFunc3x4 for 2/4 outputs.
- Check with reflect.TypeOf(fn).NumIn()/NumOut() before wrapping.
- If the function is part of a beam.DoFn path, prefer the typed DoFn registration API so signature matching is done by Beam's machinery instead of manual reflectx coercion.
Example fix
// before
f := reflectx.ToFunc3x3(func(a int, b, c string) (int, string, bool, error) { return a, b, true, nil }) // 4 outputs, panics
// after
f := reflectx.ToFunc3x4(func(a int, b, c string) (int, string, bool, error) { return a, b, true, nil }) Defensive patterns
Strategy: validation
Validate before calling
t := reflect.TypeOf(fn)
if t.NumIn() != 3 || t.NumOut() != 3 {
panic(fmt.Sprintf("expected 3-in/3-out func, got %v (%d in, %d out)", t, t.NumIn(), t.NumOut()))
}
f := reflectx.ToFunc3x3(f) Type guard
func isFunc3x3(fn any) bool {
t := reflect.TypeOf(fn)
return t != nil && t.Kind() == reflect.Func && t.NumIn() == 3 && t.NumOut() == 3
} Try / catch
func safeToFunc3x3(f reflectx.Func) (out reflectx.Func3x3, err error) {
defer func() { if r := recover(); r != nil { err = fmt.Errorf("ToFunc3x3: %v", r) } }()
out = reflectx.ToFunc3x3(f)
return
} Prevention
- Re-verify arity after any schema/PCollection change that adds or removes outputs.
- Include (T, T, error) counting discipline in code review checklists.
- Write table-driven tests that assert NumIn/NumOut for each converter target.
- Wrap converters in small typed helpers so the compiler and one assertion site cover many call sites.
When it happens
Trigger: Calling reflectx.ToFunc3x3(f) where f.Type().NumIn() != 3 (e.g. 2 or 4 params) or f.Type().NumOut() != 3 (e.g. 2 or 4 return values).
Common situations: Multi-output functions that were extended to return an extra diagnostic value (4 outputs), or trimmed to drop an output (2 outputs), during schema/PCollection changes; also hitting the wrong converter after copy-pasting a ToFuncNxM call for a function with different arity.
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
- Incompatible func type: got func %v with %v inputs and %v ou
- Incompatible func type: got func %v with %v inputs and %v ou
- Incompatible func type: got func %v with %v inputs and %v ou
- Incompatible func type: got func %v with %v inputs and %v ou
- Incompatible func type: got func %v with %v inputs and %v ou
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/cfb3a6bd5205f90a.
Report an issue: GitHub.