apache/beam · error

Incompatible func type: got func

Error message

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

What it means

ToFunc1x0 adapts a generic reflectx Func into a Func1x0 (1 input, 0 outputs, i.e. a consumer). It panics when the wrapped function's type does not have exactly 1 input and 0 outputs. The check exists so signature mismatches surface immediately at adaptation time.

Solutions

  1. Make the wrapped function take exactly 1 input and return nothing.
  2. Switch to the ToFunc/MakeFunc variant that matches the real arity (e.g. ToFunc1x1 if it returns one value).
  3. Inspect c.Type().NumIn()/NumOut() at the call site to pick the right helper.

Example fix

// before
reflectx.MakeFunc1x0(func(x int) error { return nil }) // panics: 1 output
// after
reflectx.MakeFunc1x0(func(x int) { _ = x })
Defensive patterns

Strategy: validation

Validate before calling

t := c.Type()
if t.NumIn() != 1 || t.NumOut() != 0 {
    return fmt.Errorf("func %v has %d ins/%d outs; ToFunc1x0 needs 1 in/0 outs", t, t.NumIn(), t.NumOut())
}

Type guard

func isFunc1x0(c reflectx.Func) bool {
    return c.Type().NumIn() == 1 && c.Type().NumOut() == 0
}

Try / catch

func safeToFunc1x0(c reflectx.Func) (f reflectx.Func1x0) {
    defer func() {
        if r := recover(); r != nil {
            log.Fatalf("ToFunc1x0 arity mismatch: %v", r)
        }
    }()
    return reflectx.ToFunc1x0(c)
}

Prevention

When it happens

Trigger: Calling reflectx.ToFunc1x0 or MakeFunc1x0 with a Func whose Type().NumIn() != 1 or Type().NumOut() != 0, e.g. a function returning a value or an error, or taking 2+ parameters.

Common situations: Wrapping a process-element function that returns an error; passing a function that accidentally kept a return statement after a refactor; using the wrong MakeFuncNxM helper after changing a sink's 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/946412ab364463ba. Report an issue: GitHub.

Appendix: source

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

}

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

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

func (c *shimFunc1x0) Call1x0(arg0 any) {
	ret := c.inner.Call([]any{arg0})
	_ = ret
	return
}

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

func MakeFunc1x0(fn any) Func1x0 {
	return ToFunc1x0(MakeFunc(fn))
}

type Func1x1 interface {
	Func
	Call1x1(any) any
}

type shimFunc1x1 struct {
	inner Func

View on GitHub (pinned to 12126d8942)