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

What it means

reflectx.ToFunc7x1 converts a Func to a 7-input/1-output typed function and panics on any other arity. The generated shim indexes the return slice as ret[0], so it requires exactly one output. The panic message echoes the actual func type and its input/output counts.

Source

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

}

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

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

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

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

func MakeFunc7x1(fn any) Func7x1 {
	return ToFunc7x1(MakeFunc(fn))
}

type Func7x2 interface {
	Func
	Call7x2(any, any, any, any, any, any, any) (any, any)
}

type shimFunc7x2 struct {
	inner Func

View on GitHub (pinned to 12126d8942)

Solutions

  1. Adjust the function to exactly 7 parameters and 1 return value
  2. If it returns 0 or 2+ values, switch to the matching converter (ToFunc7x0, ToFunc7x2, ...)
  3. If the input count is wrong, pick the converter for the true arity (e.g. ToFunc6x1)
  4. Wrap conversion in a recover or pre-check NumIn/NumOut in plugin-style code

Example fix

// before
func(a, b, c, d, e, f2, g any) (any, error) { ... } // 2 outputs
reflectx.ToFunc7x1(reflectx.NewFunc(fn)) // panics
// after
func(a, b, c, d, e, f2, g any) any { ... } // 1 output
reflectx.ToFunc7x1(reflectx.NewFunc(fn)) // OK
Defensive patterns

Strategy: validation

Validate before calling

t := f.Type()
if t.NumIn() != 7 || t.NumOut() != 1 {
    return fmt.Errorf("ToFunc7x1 needs 7 in / 1 out, got %d in / %d out (%v)", t.NumIn(), t.NumOut(), t)
}

Type guard

func isFunc7x1(f reflectx.Func) bool {
    t := f.Type()
    return t.NumIn() == 7 && t.NumOut() == 1
}

Try / catch

func safeToFunc7x1(f reflectx.Func) (fn reflectx.Func7x1, err error) {
    defer func() {
        if r := recover(); r != nil {
            err = fmt.Errorf("conversion failed: %v", r)
        }
    }()
    fn = reflectx.ToFunc7x1(f)
    return
}

Prevention

When it happens

Trigger: Calling ToFunc7x1 (or MakeFunc7x1) with a Func whose reflect.Type has inputs != 7 or outputs != 1, such as a 7-in/0-out sink or a 7-in/2-out function.

Common situations: Mapping functions that gained a second return value (value+error) without switching to ToFunc7x2; element-count changes in a DoFn's process signature; mismatched helper chosen in generated or copied registration code.

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/60988b71a85dd630. Report an issue: GitHub.