{"record":{"id":"b441748256caf9f8","repo":"apache/beam","slug":"panic-formatpardoerror-dofn-len-ret-5","errorCode":null,"errorMessage":"panic(formatParDoError(dofn, len(ret), 5))","messagePattern":"panic\\(formatParDoError\\(dofn, len\\(ret\\), 5\\)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/pardo.go","lineNumber":469,"sourceCode":"\t\tpanic(formatParDoError(dofn, len(ret), 3))\n\t}\n\treturn ret[0], ret[1], ret[2]\n}\n\n// ParDo4 inserts a ParDo with 4 outputs into the pipeline.\nfunc ParDo4(s Scope, dofn any, col PCollection, opts ...Option) (PCollection, PCollection, PCollection, PCollection) {\n\tret := MustN(TryParDo(s, dofn, col, opts...))\n\tif len(ret) != 4 {\n\t\tpanic(formatParDoError(dofn, len(ret), 4))\n\t}\n\treturn ret[0], ret[1], ret[2], ret[3]\n}\n\n// ParDo5 inserts a ParDo with 5 outputs into the pipeline.\nfunc ParDo5(s Scope, dofn any, col PCollection, opts ...Option) (PCollection, PCollection, PCollection, PCollection, PCollection) {\n\tret := MustN(TryParDo(s, dofn, col, opts...))\n\tif len(ret) != 5 {\n\t\tpanic(formatParDoError(dofn, len(ret), 5))\n\t}\n\treturn ret[0], ret[1], ret[2], ret[3], ret[4]\n}\n\n// ParDo6 inserts a ParDo with 6 outputs into the pipeline.\nfunc ParDo6(s Scope, dofn any, col PCollection, opts ...Option) (PCollection, PCollection, PCollection, PCollection, PCollection, PCollection) {\n\tret := MustN(TryParDo(s, dofn, col, opts...))\n\tif len(ret) != 6 {\n\t\tpanic(formatParDoError(dofn, len(ret), 6))\n\t}\n\treturn ret[0], ret[1], ret[2], ret[3], ret[4], ret[5]\n}\n\n// ParDo7 inserts a ParDo with 7 outputs into the pipeline.\nfunc ParDo7(s Scope, dofn any, col PCollection, opts ...Option) (PCollection, PCollection, PCollection, PCollection, PCollection, PCollection, PCollection) {\n\tret := MustN(TryParDo(s, dofn, col, opts...))\n\tif len(ret) != 7 {\n\t\tpanic(formatParDoError(dofn, len(ret), 7))","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/pardo.go#L451-L487","documentation":"Panic raised by the typed ParDo5 convenience wrapper when the underlying TryParDo returned a number of output PCollections other than 5 (as reported by formatParDoError). It means the DoFn's emitted outputs (or the options given) did not match the fixed 5-output arity this helper promises; the panic occurs at pipeline construction, not at runtime.","triggerScenarios":"Calling beam.ParDo5 with a DoFn whose ProcessElement emits fewer or more than 5 outputs.","commonSituations":"Off-by-one when adding a new output tag to a 4-output DoFn; reusing a generic fan-out DoFn across pipelines with different output counts; copy-paste of ParDo4 call sites upgraded to ParDo5 without touching the DoFn.","solutions":["Update the DoFn's ProcessElement to emit exactly 5 outputs.","Or select the ParDoN helper matching the DoFn's real output count.","Prefer TryParDo + MustN when the count is dynamic, to get a returned error instead of a panic."],"exampleFix":"// before: 4-output DoFn used with ParDo5\nfunc (f *fn) ProcessElement(e string) (string, string, string, string) { ... }\nbeam.ParDo5(s, &fn{}, col)\n\n// after: emit a fifth output\nfunc (f *fn) ProcessElement(e string) (string, string, string, string, string) { ... }\nbeam.ParDo5(s, &fn{}, col)","handlingStrategy":"validation","validationCode":"if outputsOfMyDoFn != 5 { log.Fatalf(\"expected 5 outputs, got %d\", outputsOfMyDoFn) }","typeGuard":null,"tryCatchPattern":"defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"ParDo5 failed: %v\", r) } }()","preventionTips":["Recount emits after every DoFn refactor","Add a unit test constructing the pipeline to catch arity panics in CI","Use TryParDo to surface arity problems as errors"],"tags":["go","apache-beam","pardo","panic","signature-mismatch"],"backgroundTag":"invalid-argument-value","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"}