{"record":{"id":"86cd2d2abdcd1929","repo":"apache/beam","slug":"invalid-pcollection","errorCode":null,"errorMessage":"invalid pcollection","messagePattern":"invalid pcollection","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/gbk.go","lineNumber":136,"sourceCode":"// A Reshuffle will force a break in the optimized pipeline. Consequently,\n// this operation should be used sparingly, only after determining that the\n// pipeline without reshuffling is broken in some way and performing an extra\n// operation is worth the cost.\nfunc Reshuffle(s Scope, col PCollection) PCollection {\n\treturn Must(TryReshuffle(s, col))\n}\n\n// TryReshuffle inserts a Reshuffle into the pipeline, and returns an error if\n// the pcollection's unable to be reshuffled.\nfunc TryReshuffle(s Scope, col PCollection) (PCollection, error) {\n\taddContext := func(err error, s Scope) error {\n\t\treturn errors.WithContextf(err, \"inserting Reshard in scope %s\", s)\n\t}\n\tif !s.IsValid() {\n\t\treturn PCollection{}, addContext(errors.New(\"invalid scope\"), s)\n\t}\n\tif !col.IsValid() {\n\t\treturn PCollection{}, addContext(errors.New(\"invalid pcollection\"), s)\n\t}\n\tedge, err := graph.NewReshuffle(s.real, s.scope, col.n)\n\tif err != nil {\n\t\treturn PCollection{}, addContext(err, s)\n\t}\n\tcol.n.WindowingStrategy()\n\tret := PCollection{edge.Output[0].To}\n\tret.SetCoder(NewCoder(ret.Type()))\n\treturn ret, nil\n}\n","sourceCodeStart":118,"sourceCodeEnd":147,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/gbk.go#L118-L147","documentation":"TryReshuffle requires a valid input PCollection; if col is the zero PCollection (e.g. returned from a failed or skipped construction), the reshuffle has nothing to reshuffle and the call fails with 'invalid pcollection', wrapped with the Reshard scope context.","triggerScenarios":"beam.Reshuffle(s, col) / TryReshuffle where col == PCollection{} — usually the result of ignoring an error from a transform that returned PCollection{}, or a struct field of type PCollection that was never assigned.","commonSituations":"Chaining transforms where an earlier step failed and returned an empty PCollection that was then passed onward; conditional logic producing a PCollection only on one branch; typos causing the wrong (uninitialized) variable to be passed.","solutions":["Check col.IsValid() before calling Reshuffle and fix the upstream transform that produced the invalid collection.","Always handle the error return of transform calls — do not use the zero PCollection they return on failure.","Print/log the PCollection's validity (and upstream errors) where it is produced to find the broken step."],"exampleFix":"// before\nout, _ := someTransform(s, in) // error ignored, out invalid\nreshuffled := beam.Reshuffle(s, out) // invalid pcollection\n\n// after\nout, err := someTransform(s, in)\nif err != nil {\n\treturn err\n}\nreshuffled := beam.Reshuffle(s, out)","handlingStrategy":"validation","validationCode":"if !col.IsValid() {\n\treturn fmt.Errorf(\"cannot Reshuffle: input pcollection is invalid (check upstream transform errors)\")\n}\nout := beam.Reshuffle(s, col)","typeGuard":"func validPCol(c beam.PCollection) bool { return c.IsValid() }","tryCatchPattern":null,"preventionTips":["Always check err from transform calls before using the returned PCollection.","Avoid conditional branches that can leave a PCollection variable unassigned.","Validate inputs with IsValid() at stage boundaries."],"tags":["go","apache-beam","reshuffle","invalid-pcollection"],"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-20T03:17:13.778Z"}