apache/beam · error
panic(formatParDoError(dofn, len(ret), 4))
Error message
panic(formatParDoError(dofn, len(ret), 4))
What it means
ParDo4 applies a DoFn expected to produce exactly 4 outputs. If TryParDo returns a count other than 4, the library panics via formatParDoError with the DoFn name, actual count, and expected count of 4.
Source
Thrown at sdks/go/pkg/beam/pardo.go:460
panic(formatParDoError(dofn, len(ret), 2))
}
return ret[0], ret[1]
}
// ParDo3 inserts a ParDo with 3 outputs into the pipeline.
func ParDo3(s Scope, dofn any, col PCollection, opts ...Option) (PCollection, PCollection, PCollection) {
ret := MustN(TryParDo(s, dofn, col, opts...))
if len(ret) != 3 {
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))View on GitHub (pinned to 12126d8942)
Solutions
- Make the DoFn's ProcessElement emit exactly 4 outputs (4 emit fields or 4 return values).
- Or call the ParDoN variant that matches the DoFn's actual output count.
- Use TryParDo to get an error instead of a panic when the output count is uncertain.
Example fix
// before: 3-output DoFn used with ParDo4
func (f *fn) ProcessElement(x int) (int, int, int) { ... }
beam.ParDo4(s, &fn{}, col)
// after: add a fourth output
func (f *fn) ProcessElement(x int) (int, int, int, int) { ... }
beam.ParDo4(s, &fn{}, col) Defensive patterns
Strategy: validation
Validate before calling
// confirm 4 outputs exist before ParDo4
if outputsOfMyDoFn != 4 {
log.Fatalf("expected 4 outputs, got %d", outputsOfMyDoFn)
} Try / catch
defer func() { if r := recover(); r != nil { err = fmt.Errorf("ParDo4 failed: %v", r) } }() Prevention
- Match ParDoN number to the DoFn's emit arity exactly
- Prefer ParDoN/TryParDo when arity may change
- Review panic text from formatParDoError: it names DoFn, actual, expected counts
When it happens
Trigger: Calling beam.ParDo4 (directly or via CoGBK/ReshuffleKV paths) with a DoFn whose ProcessElement does not emit exactly 4 outputs.
Common situations: DoFn was originally single-output and was reused with ParDo4; an emit parameter was removed during refactor; confusion between main output plus tag outputs versus pure emit-based outputs.
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), 5))
- 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/69d8e97fcb691468.
Report an issue: GitHub.