apache/beam · error

invoker: %v has > 5 return values, which is not permitted

Error message

invoker: %v has > 5 return values, which is not permitted

What it means

Beam's reflection-based invoker (fn_arity.go) supports user functions with at most 5 return values, with dedicated ret1..ret5 dispatch paths. If a function somehow reaches the invoker with more than 5 return values, the arity switch falls through and panics, since no dispatcher exists.

Source

Thrown at sdks/go/pkg/beam/core/runtime/exec/fn_arity.go:325

			ret := n.fn.Fn.Call(n.args)

			// (5) Return direct output, if any. Input timestamp and windows are implicitly
			// propagated.
			switch len(ret) {
			case 0:
				return nil, nil
			case 1:
				return n.ret1(pn, ws, ts, ret[0])
			case 2:
				return n.ret2(pn, ws, ts, ret[0], ret[1])
			case 3:
				return n.ret3(pn, ws, ts, ret[0], ret[1], ret[2])
			case 4:
				return n.ret4(pn, ws, ts, ret[0], ret[1], ret[2], ret[3])
			case 5:
				return n.ret5(pn, ws, ts, ret[0], ret[1], ret[2], ret[3], ret[4])
			}
			panic(fmt.Sprintf("invoker: %v has > 5 return values, which is not permitted", n.fn.Fn.Name()))
		}
	}
}

View on GitHub (pinned to 12126d8942)

Solutions

  1. Rewrite the function to return at most 5 values — bundle extra outputs into a struct.
  2. Split the function's outputs: emit extra results via an emitter/PTypes collect parameter instead of return values.
  3. Check Beam version docs for the supported arity limits and the earlier arity validation that should have rejected this sooner.

Example fix

// before
func myFn(e string) (int, int, int, int, int, int) { ... } // >5 returns
// after
type Stats struct{ A, B, C, D, E, F int }
func myFn(e string) (int, int, int, int, Stats) { ... }
Defensive patterns

Strategy: validation

Validate before calling

if reflect.TypeOf(fn).NumOut() > 5 {
	return fmt.Errorf("function %T has %d return values; max supported is 5", fn, reflect.TypeOf(fn).NumOut())
}

Type guard

func tooManyReturns(fn any) bool {
	t := reflect.TypeOf(fn)
	return t != nil && t.Kind() == reflect.Func && t.NumOut() > 5
}

Prevention

When it happens

Trigger: Registering/invoking a DoFn or combine function whose signature has 6 or more return values and which slips past earlier arity validation atFn stage.

Common situations: Rare in practice: user functions with huge signatures, code generated functions, or an API change allowing more returns than the invoker supports.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/0ba0f4cfa861c58b. Report an issue: GitHub.