apache/beam · error
panic(formatParDoError(dofn, len(ret), 5))
Error message
panic(formatParDoError(dofn, len(ret), 5))
What it means
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.
Source
Thrown at sdks/go/pkg/beam/pardo.go:469
panic(formatParDoError(dofn, len(ret), 3))
}
return ret[0], ret[1], ret[2]
}
// ParDo4 inserts a ParDo with 4 outputs into the pipeline.
func ParDo4(s Scope, dofn any, col PCollection, opts ...Option) (PCollection, PCollection, PCollection, PCollection) {
ret := MustN(TryParDo(s, dofn, col, opts...))
if len(ret) != 4 {
panic(formatParDoError(dofn, len(ret), 4))
}
return ret[0], ret[1], ret[2], ret[3]
}
// ParDo5 inserts a ParDo with 5 outputs into the pipeline.
func ParDo5(s Scope, dofn any, col PCollection, opts ...Option) (PCollection, PCollection, PCollection, PCollection, PCollection) {
ret := MustN(TryParDo(s, dofn, col, opts...))
if len(ret) != 5 {
panic(formatParDoError(dofn, len(ret), 5))
}
return ret[0], ret[1], ret[2], ret[3], ret[4]
}
// ParDo6 inserts a ParDo with 6 outputs into the pipeline.
func ParDo6(s Scope, dofn any, col PCollection, opts ...Option) (PCollection, PCollection, PCollection, PCollection, PCollection, PCollection) {
ret := MustN(TryParDo(s, dofn, col, opts...))
if len(ret) != 6 {
panic(formatParDoError(dofn, len(ret), 6))
}
return ret[0], ret[1], ret[2], ret[3], ret[4], ret[5]
}
// ParDo7 inserts a ParDo with 7 outputs into the pipeline.
func ParDo7(s Scope, dofn any, col PCollection, opts ...Option) (PCollection, PCollection, PCollection, PCollection, PCollection, PCollection, PCollection) {
ret := MustN(TryParDo(s, dofn, col, opts...))
if len(ret) != 7 {
panic(formatParDoError(dofn, len(ret), 7))View on GitHub (pinned to 12126d8942)
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.
Example fix
// before: 4-output DoFn used with ParDo5
func (f *fn) ProcessElement(e string) (string, string, string, string) { ... }
beam.ParDo5(s, &fn{}, col)
// after: emit a fifth output
func (f *fn) ProcessElement(e string) (string, string, string, string, string) { ... }
beam.ParDo5(s, &fn{}, col) Defensive patterns
Strategy: validation
Validate before calling
if outputsOfMyDoFn != 5 { log.Fatalf("expected 5 outputs, got %d", outputsOfMyDoFn) } Try / catch
defer func() { if r := recover(); r != nil { err = fmt.Errorf("ParDo5 failed: %v", r) } }() Prevention
- 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
When it happens
Trigger: Calling beam.ParDo5 with a DoFn whose ProcessElement emits fewer or more than 5 outputs.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- panic(formatParDoError(dofn, len(ret), 3))
- panic(formatParDoError(dofn, len(ret), 4))
- panic(formatParDoError(dofn, len(ret), 6))
- panic(formatParDoError(dofn, len(ret), 7))
- Failed to optimize AddInput for combiner %v. Failed to infer
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/b441748256caf9f8.
Report an issue: GitHub.