{"record":{"id":"01da96fc4cbdc4b2","repo":"apache/beam","slug":"panic-formatpardoerror-dofn-len-ret-0","errorCode":null,"errorMessage":"panic(formatParDoError(dofn, len(ret), 0))","messagePattern":"panic\\(formatParDoError\\(dofn, len\\(ret\\), 0\\)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/pardo.go","lineNumber":137,"sourceCode":"\tvar ret []PCollection\n\tfor _, out := range edge.Output {\n\t\tc := PCollection{out.To}\n\t\tc.SetCoder(NewCoder(c.Type()))\n\t\tret = append(ret, c)\n\t}\n\treturn ret, nil\n}\n\n// ParDoN inserts a ParDo with any number of outputs into the pipeline.\nfunc ParDoN(s Scope, dofn any, col PCollection, opts ...Option) []PCollection {\n\treturn MustN(TryParDo(s, dofn, col, opts...))\n}\n\n// ParDo0 inserts a ParDo with zero output transform into the pipeline.\nfunc ParDo0(s Scope, dofn any, col PCollection, opts ...Option) {\n\tret := MustN(TryParDo(s, dofn, col, opts...))\n\tif len(ret) != 0 {\n\t\tpanic(formatParDoError(dofn, len(ret), 0))\n\t}\n}\n\n// ParDo is the core element-wise PTransform in Apache Beam, invoking a\n// user-specified function on each of the elements of the input PCollection\n// to produce zero or more output elements, all of which are collected into\n// the output PCollection. Use one of the ParDo variants for a different\n// number of output PCollections. The PCollections do not need to have the\n// same types.\n//\n// Elements are processed independently, and possibly in parallel across\n// distributed cloud resources. The ParDo processing style is similar to what\n// happens inside the \"Mapper\" or \"Reducer\" class of a MapReduce-style\n// algorithm.\n//\n// # DoFns\n//\n// The function to use to process each element is specified by a DoFn, either as","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/pardo.go#L119-L155","documentation":"ParDo0 applies a ParDo transform that must produce exactly zero output PCollections. After TryParDo succeeds, if the number of returned PCollections is not 0, it panics with a formatted ParDo error describing the dofn and the actual vs expected output count.","triggerScenarios":"Calling beam.ParDo0 with a DoFn whose signature yields one or more output PCollections (e.g. a function that returns a value) instead of returning nothing.","commonSituations":"Reusing a DoFn written for beam.ParDo/ParDo2 with ParDo0, or changing a DoFn's return signature after switching the apply call, causing a count mismatch.","solutions":["Change the DoFn to return no values (side-effect-only, e.g. via an output sink)","Use beam.ParDo instead if the DoFn legitimately produces one output","Match the ParDo0/ParDo/ParDoN variant to the DoFn's actual return arity"],"exampleFix":"// before\nbeam.ParDo0(s, func(x string) string { return x }, col) // 1 output, expects 0\n// after\nbeam.ParDo(s, func(x string) string { return x }, col)","handlingStrategy":"type-guard","validationCode":"// Check DoFn signature arity before applying\n// A ParDo0 DoFn must produce no outputs (no return values beyond error conventions)","typeGuard":"func isZeroOutputDoFn(fn any) bool {\n    t := reflect.TypeOf(fn)\n    for t.Kind() == reflect.Ptr {\n        t = t.Elem()\n    }\n    m, ok := t.MethodByName(\"ProcessElement\")\n    if !ok { return false }\n    // heuristic: count emit params and return values against expected outputs\n    return m.Type.NumOut() == 0\n}","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        err = fmt.Errorf(\"ParDo0 arity mismatch: %v\", r)\n    }\n}()","preventionTips":["Match the ParDo0/ParDo/ParDoN helper to the DoFn's output count","Re-check call sites after changing a DoFn's return signature","Write pipeline-construction tests that exercise each transform once"],"tags":["go","beam","pardo","arity"],"backgroundTag":"unexpected-response-shape","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"}