apache/beam · error
Incompatible func type: got func
Error message
Incompatible func type: got func %v with %v inputs and %v outputs, want 1 inputs and 2 outputs
What it means
ToFunc1x2 adapts a generic reflectx Func into a Func1x2 (1 input, 2 outputs, typically a value+emit or key/value pair function). It panics unless the wrapped function has exactly 1 input and 2 outputs, surfacing signature mismatches immediately.
Solutions
- Make the wrapped function take 1 input and return exactly 2 values.
- Pick the correct ToFunc/MakeFuncNxM variant for the real arity.
- Verify with c.Type().NumIn()/NumOut() before adapting.
Example fix
// before
reflectx.MakeFunc1x2(func(s string) string { return s }) // panics: 1 output
// after
reflectx.MakeFunc1x2(func(s string) (string, string) { return s, s }) Defensive patterns
Strategy: validation
Validate before calling
t := c.Type()
if t.NumIn() != 1 || t.NumOut() != 2 {
return fmt.Errorf("func %v has %d ins/%d outs; ToFunc1x2 needs 1 in/2 outs", t, t.NumIn(), t.NumOut())
} Type guard
func isFunc1x2(c reflectx.Func) bool {
return c.Type().NumIn() == 1 && c.Type().NumOut() == 2
} Try / catch
func safeToFunc1x2(c reflectx.Func) (f reflectx.Func1x2) {
defer func() {
if r := recover(); r != nil {
log.Fatalf("ToFunc1x2 arity mismatch: %v", r)
}
}()
return reflectx.ToFunc1x2(c)
} Prevention
- Verify decoder/encoder functions return exactly (T, error)-shaped pairs matching the 1x2 contract expected by makeDecoder/makeEncoder.
- Update both the function and its MakeFuncNxM call in the same commit.
- Add arity assertions in package tests.
When it happens
Trigger: Calling reflectx.ToFunc1x2, MakeFunc1x2, or the coder makeDecoder/makeEncoder paths with a Func whose Type().NumIn() != 1 or Type().NumOut() != 2.
Common situations: Writing a decoder/encoder that forgot one of its two return values; a flatmap-style function changed to return 3 values; wrapping a function that returns only a value without the second element.
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
- 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/cda0fa493deb1efc.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/util/reflectx/calls.go:352
}
func (c *shimFunc1x2) Type() reflect.Type {
return c.inner.Type()
}
func (c *shimFunc1x2) Call(args []any) []any {
return c.inner.Call(args)
}
func (c *shimFunc1x2) Call1x2(arg0 any) (any, any) {
ret := c.inner.Call([]any{arg0})
_ = ret
return ret[0], ret[1]
}
func ToFunc1x2(c Func) Func1x2 {
if c.Type().NumIn() != 1 || c.Type().NumOut() != 2 {
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 1 inputs and 2 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
}
if sc, ok := c.(Func1x2); ok {
return sc
}
return &shimFunc1x2{inner: c}
}
func MakeFunc1x2(fn any) Func1x2 {
return ToFunc1x2(MakeFunc(fn))
}
type Func1x3 interface {
Func
Call1x3(any) (any, any, any)
}
type shimFunc1x3 struct {
inner FuncView on GitHub (pinned to 12126d8942)