{"record":{"id":"0ba0f4cfa861c58b","repo":"apache/beam","slug":"invoker-v-has-5-return-values-which-is-not-permitted","errorCode":null,"errorMessage":"invoker: %v has > 5 return values, which is not permitted","messagePattern":"invoker: (.+?) has > 5 return values, which is not permitted","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/exec/fn_arity.go","lineNumber":325,"sourceCode":"\t\t\tret := n.fn.Fn.Call(n.args)\n\n\t\t\t// (5) Return direct output, if any. Input timestamp and windows are implicitly\n\t\t\t// propagated.\n\t\t\tswitch len(ret) {\n\t\t\tcase 0:\n\t\t\t\treturn nil, nil\n\t\t\tcase 1:\n\t\t\t\treturn n.ret1(pn, ws, ts, ret[0])\n\t\t\tcase 2:\n\t\t\t\treturn n.ret2(pn, ws, ts, ret[0], ret[1])\n\t\t\tcase 3:\n\t\t\t\treturn n.ret3(pn, ws, ts, ret[0], ret[1], ret[2])\n\t\t\tcase 4:\n\t\t\t\treturn n.ret4(pn, ws, ts, ret[0], ret[1], ret[2], ret[3])\n\t\t\tcase 5:\n\t\t\t\treturn n.ret5(pn, ws, ts, ret[0], ret[1], ret[2], ret[3], ret[4])\n\t\t\t}\n\t\t\tpanic(fmt.Sprintf(\"invoker: %v has > 5 return values, which is not permitted\", n.fn.Fn.Name()))\n\t\t}\n\t}\n}\n","sourceCodeStart":307,"sourceCodeEnd":329,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/fn_arity.go#L307-L329","documentation":"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.","triggerScenarios":"Registering/invoking a DoFn or combine function whose signature has 6 or more return values and which slips past earlier arity validation atFn stage.","commonSituations":"Rare in practice: user functions with huge signatures, code generated functions, or an API change allowing more returns than the invoker supports.","solutions":["Rewrite the function to return at most 5 values — bundle extra outputs into a struct.","Split the function's outputs: emit extra results via an emitter/PTypes collect parameter instead of return values.","Check Beam version docs for the supported arity limits and the earlier arity validation that should have rejected this sooner."],"exampleFix":"// before\nfunc myFn(e string) (int, int, int, int, int, int) { ... } // >5 returns\n// after\ntype Stats struct{ A, B, C, D, E, F int }\nfunc myFn(e string) (int, int, int, int, Stats) { ... }","handlingStrategy":"validation","validationCode":"if reflect.TypeOf(fn).NumOut() > 5 {\n\treturn fmt.Errorf(\"function %T has %d return values; max supported is 5\", fn, reflect.TypeOf(fn).NumOut())\n}","typeGuard":"func tooManyReturns(fn any) bool {\n\tt := reflect.TypeOf(fn)\n\treturn t != nil && t.Kind() == reflect.Func && t.NumOut() > 5\n}","tryCatchPattern":null,"preventionTips":["Design DoFn/combine functions with at most 5 return values.","Group related outputs into a struct instead of long return lists.","Prefer emitters (PCollection output params) over additional return values."],"tags":["go","panic","beam","reflection","function-arity"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}