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

What it means

reflectx.ToFunc5x0 wraps a reflectx.Func into a Func5x0 (5 inputs, no return values). It panics with this message if the wrapped func's reflect.Type does not have exactly 5 inputs and 0 outputs. This guarantees the fast-path shim can call the function without type or arity errors.

Solutions

  1. Make the function take exactly 5 inputs and return nothing (drop or move any return values).
  2. Switch to the correct ToFuncN x M helper matching the real signature, e.g. ToFunc5x1 for a single error return.
  3. Verify the DoFn's ProcessElement signature matches the 5x0 shape expected by the pipeline step.

Example fix

// before
func fn(a A, b B, c C, d D, e E) error { ... }
reflectx.ToFunc5x0(fn) // panics: 1 output

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

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Calling reflectx.ToFunc5x0(c) where c.Type().NumIn() != 5 or c.Type().NumOut() != 0. E.g. registering a sink-like function that returns values, or one that takes fewer/more than 5 arguments.

Common situations: Sink/consumer DoFns that accidentally return a value; passing a 5-input function with an error return into a ToFunc5x0 conversion; copy-pasted registration using the wrong ToFuncNxM helper after changing input count.

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/1c64b01fa97c6247. Report an issue: GitHub.

Appendix: source

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

}

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

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

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

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

func MakeFunc5x0(fn any) Func5x0 {
	return ToFunc5x0(MakeFunc(fn))
}

type Func5x1 interface {
	Func
	Call5x1(any, any, any, any, any) any
}

type shimFunc5x1 struct {
	inner Func

View on GitHub (pinned to 12126d8942)