apache/beam · error

Incompatible func type: got func

Error message

Incompatible func type: got func %v with %v inputs and %v outputs, want 8 inputs and 1 outputs

What it means

reflectx.ToFunc8x1 wraps a Func as an 8-input/1-output function, panicking on any other arity. The shim returns ret[0], so exactly one output is required. The panic includes the offending reflect.Type and its input/output counts, firing before the pipeline runs.

Solutions

  1. Change the function to exactly 8 parameters and 1 return value
  2. Switch to the converter matching actual arity (ToFunc8x0, ToFunc8x2, ...)
  3. Correct the input count by choosing e.g. ToFunc7x1 if 8 is wrong
  4. Validate NumIn/NumOut before conversion in generic code

Example fix

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

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Calling ToFunc8x1 (or MakeFunc8x1) with a Func whose signature has inputs != 8 or outputs != 1, e.g. an 8-in/0-out sink or 8-in/2-out function.

Common situations: Mapping functions that dropped or added a return value; signature growth to 8 parameters after adding a timestamp/window arg while keeping an old converter; copied registrations targeting the wrong FuncNxM.

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

Appendix: source

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

}

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

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

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

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

func MakeFunc8x1(fn any) Func8x1 {
	return ToFunc8x1(MakeFunc(fn))
}

type Func8x2 interface {
	Func
	Call8x2(any, any, any, any, any, any, any, any) (any, any)
}

type shimFunc8x2 struct {
	inner Func

View on GitHub (pinned to 12126d8942)