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 1 outputs

What it means

reflectx.ToFunc5x1 wraps a reflectx.Func into a Func5x1 (5 inputs, 1 output). It panics with this message when the func's reflect.Type does not have exactly 5 inputs and 1 output. The check exists so the shim can safely unpack the single return value.

Solutions

  1. Adjust the function to take 5 inputs and return exactly 1 value (drop the error return or fold it in).
  2. Use ToFunc5x2 (or the matching variant) if the function legitimately returns 2 values.
  3. Re-check the expected signature in the calling Beam registration code and align the function to it.

Example fix

// before
func fn(a A, b B, c C, d D, e E) (T, error) { ... }
reflectx.ToFunc5x1(fn) // panics: 2 outputs

// after
func fn(a A, b B, c C, d D, e E) T { ... }
reflectx.ToFunc5x1(fn)
Defensive patterns

Strategy: validation

Validate before calling

fn := reflect.TypeOf(fnAny)
if fn.Kind() == reflect.Func && fn.NumIn() == 5 && fn.NumOut() == 1 {
    _ = reflectx.ToFunc5x1(fnAny)
}

Type guard

func isFunc5x1(f interface{}) bool {
    t := reflect.TypeOf(f)
    return t != nil && t.Kind() == reflect.Func && t.NumIn() == 5 && t.NumOut() == 1
}

Try / catch

func safeToFunc5x1(c reflectx.Func) (f reflectx.Func5x1, err error) {
    defer func() {
        if r := recover(); r != nil {
            err = fmt.Errorf("ToFunc5x1 failed: %v", r)
        }
    }()
    return reflectx.ToFunc5x1(c), nil
}

Prevention

When it happens

Trigger: Calling reflectx.ToFunc5x1(c) where c.Type().NumIn() != 5 or c.Type().NumOut() != 1. Commonly a map-style function with 5 inputs returning 2 values (element + error) or returning nothing.

Common situations: Beam DoFns whose ProcessElement returns (T, error) instead of a single value; arity drift after adding an input parameter; using ToFunc5x1 where the pipeline registered a 5x2 signature.

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


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/310be809a13d4276. Report an issue: GitHub.

Appendix: source

Thrown at sdks/go/pkg/beam/core/util/reflectx/calls.go:1131

}

func (c *shimFunc5x1) Type() reflect.Type {
	return c.inner.Type()
}

func (c *shimFunc5x1) Call(args []any) []any {
	return c.inner.Call(args)
}

func (c *shimFunc5x1) Call5x1(arg0, arg1, arg2, arg3, arg4 any) any {
	ret := c.inner.Call([]any{arg0, arg1, arg2, arg3, arg4})
	_ = ret
	return ret[0]
}

func ToFunc5x1(c Func) Func5x1 {
	if c.Type().NumIn() != 5 || c.Type().NumOut() != 1 {
		panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 5 inputs and 1 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
	}
	if sc, ok := c.(Func5x1); ok {
		return sc
	}
	return &shimFunc5x1{inner: c}
}

func MakeFunc5x1(fn any) Func5x1 {
	return ToFunc5x1(MakeFunc(fn))
}

type Func5x2 interface {
	Func
	Call5x2(any, any, any, any, any) (any, any)
}

type shimFunc5x2 struct {
	inner Func

View on GitHub (pinned to 12126d8942)