{"record":{"id":"6e6f43d9aa8a6d45","repo":"apache/beam","slug":"too-many-return-values-v","errorCode":null,"errorMessage":"too many return values: %v","messagePattern":"too many return values: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/bind.go","lineNumber":112,"sourceCode":"\treturn inbound, kinds, outbound, out, nil\n}\n\nfunc findOutbound(fn *funcx.Fn) ([]typex.FullType, error) {\n\tret := trimIllegal(returnTypes(funcx.SubReturns(fn.Ret, fn.Returns(funcx.RetValue)...)))\n\tparams := funcx.SubParams(fn.Param, fn.Params(funcx.FnEmit)...)\n\n\tvar outbound []typex.FullType\n\n\t// The direct output is the \"main\" output, if any.\n\tswitch len(ret) {\n\tcase 0:\n\t\tbreak // ok: no direct output.\n\tcase 1:\n\t\toutbound = append(outbound, typex.New(ret[0]))\n\tcase 2:\n\t\toutbound = append(outbound, typex.NewKV(typex.New(ret[0]), typex.New(ret[1])))\n\tdefault:\n\t\treturn nil, errors.Errorf(\"too many return values: %v\", ret)\n\t}\n\n\tfor _, param := range params {\n\t\tvalues, _ := funcx.UnfoldEmit(param.T)\n\t\ttrimmed := trimIllegal(values)\n\t\tif len(trimmed) == 2 {\n\t\t\toutbound = append(outbound, typex.NewKV(typex.New(trimmed[0]), typex.New(trimmed[1])))\n\t\t} else {\n\t\t\toutbound = append(outbound, typex.New(trimmed[0]))\n\t\t}\n\t}\n\treturn outbound, nil\n}\n\nfunc returnTypes(list []funcx.ReturnParam) []reflect.Type {\n\tvar ret []reflect.Type\n\tfor _, elm := range list {\n\t\tret = append(ret, elm.T)","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/bind.go#L94-L130","documentation":"findOutbound in bind.go converts a function's return values into the outbound type: 0 returns means no output, 1 becomes a plain type, 2 becomes a KV, and any other count is rejected. This error is returned when a DoFn process method returns 3 or more values, which the framework cannot represent.","triggerScenarios":"Registering a DoFn whose ProcessElement returns 3+ values, e.g. (KV, T, error) or (A, B, C, error), via graph.Bind/newDoFnNode during pipeline construction.","commonSituations":"Wanting to emit multiple distinct outputs from one method - developers return them instead of using separate emitters; porting code that returns a tuple plus error; accidental extra return of a debug value.","solutions":["Reduce returns to at most two values (single type or KV) plus the allowed error/context forms.","Use emit functions (func(X) emitter parameters) to produce multiple outputs instead of multiple return values.","Pack multiple values into a struct or beam KV type and return that single value."],"exampleFix":"// before\nfunc (f *myFn) ProcessElement(ctx context.Context, s string) (int, string, error) { ... } // 3 returns\n// after\nfunc (f *myFn) ProcessElement(s string, emitStr func(string)) (int, error) { emitStr(s); return len(s), nil }","handlingStrategy":"validation","validationCode":"if t := reflect.TypeOf(fn); t.NumOut() > 3 { // e.g. 2 values + error\n    return fmt.Errorf(\"fn returns %d values; max supported is a single value or KV (plus error)\", t.NumOut())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Return at most one value or a KV from process methods.","Use emitter functions for multiple outputs.","Model multi-field results as a struct or beam.KV."],"tags":["go","beam","dofn","signature-validation"],"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"}