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

What it means

reflectx.ToFunc6x0 wraps a reflectx.Func into a Func6x0 (6 inputs, no outputs). It panics with this message if the func's reflect.Type does not have exactly 6 inputs and 0 outputs, ensuring the void-returning shim can invoke it safely.

Solutions

  1. Change the function to take exactly 6 inputs and return nothing.
  2. Use ToFunc6x1 (or appropriate variant) if the function returns values.
  3. Verify the pipeline step expects a 6x0 signature and align parameters accordingly.

Example fix

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

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

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Calling reflectx.ToFunc6x0(c) where c.Type().NumIn() != 6 or c.Type().NumOut() != 0 — e.g. a 6-input function that returns an error, or a 5-input void function.

Common situations: Sink DoFns with many parameters (context, event time, key, value, emit) that also return an error; arity mismatch after adding a parameter without updating registration to the right NxM helper.

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/8571138bf67afd70. Report an issue: GitHub.

Appendix: source

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

}

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

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

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

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

func MakeFunc6x0(fn any) Func6x0 {
	return ToFunc6x0(MakeFunc(fn))
}

type Func6x1 interface {
	Func
	Call6x1(any, any, any, any, any, any) any
}

type shimFunc6x1 struct {
	inner Func

View on GitHub (pinned to 12126d8942)