{"record":{"id":"08943c972ce3104f","repo":"apache/beam","slug":"invalid-pcollection-to-cogbk-index-v","errorCode":null,"errorMessage":"invalid pcollection to CoGBK: index %v","messagePattern":"invalid pcollection to CoGBK: index (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/gbk.go","lineNumber":81,"sourceCode":"\treturn Must(TryCoGroupByKey(s, cols...))\n}\n\nfunc addCoGBKCtx(err error, s Scope) error {\n\treturn errors.WithContextf(err, \"inserting CoGroupByKey in scope %s\", s)\n}\n\n// TryCoGroupByKey inserts a CoGBK transform into the pipeline. Returns\n// an error on failure.\nfunc TryCoGroupByKey(s Scope, cols ...PCollection) (PCollection, error) {\n\tif !s.IsValid() {\n\t\treturn PCollection{}, addCoGBKCtx(errors.New(\"invalid scope\"), s)\n\t}\n\tif len(cols) < 1 {\n\t\treturn PCollection{}, addCoGBKCtx(errors.New(\"need at least 1 pcollection\"), s)\n\t}\n\tfor i, in := range cols {\n\t\tif !in.IsValid() {\n\t\t\treturn PCollection{}, addCoGBKCtx(errors.Errorf(\"invalid pcollection to CoGBK: index %v\", i), s)\n\t\t}\n\t}\n\n\tvar in []*graph.Node\n\tfor _, s := range cols {\n\t\tin = append(in, s.n)\n\t}\n\n\tedge, err := graph.NewCoGBK(s.real, s.scope, in)\n\tif err != nil {\n\t\treturn PCollection{}, err\n\t}\n\tret := PCollection{edge.Output[0].To}\n\tret.SetCoder(NewCoder(ret.Type()))\n\treturn ret, nil\n}\n\n// Reshuffle copies a PCollection of the same kind and using the same element","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/gbk.go#L63-L99","documentation":"TryCoGroupByKey (sdks/go/pkg/beam/gbk.go) validates each input PCollection before constructing the CoGBK node; an invalid input at index i produces this error, wrapped with scope context via addCoGBKCtx. It is raised by TryGroupByKey and CoGroupByKey when any keyed collection passed in is a zero value or not tied to a valid scope.","triggerScenarios":"Calling beam.CoGroupByKey or beam.TryGroupByKey with a zero-value or uninitialized PCollection among the cols inputs.","commonSituations":"Assembling multiple PCollections for a join where one side of the join was never produced (skipped transform branch), or a typo assigning to the wrong variable.","solutions":["Check the collection at the reported index was produced by a valid keyed transform (e.g. beam.ParDo/KV output).","Validate with in.IsValid() before invoking CoGroupByKey.","Prefer beam.TryCoGroupByKey/TryGroupByKey to receive an error rather than a panic.","Review the scope context appended by addCoGBKCtx to locate the failing scope in the pipeline."],"exampleFix":"// before\nvar left beam.PCollection\nbeam.CoGroupByKey(s, left, right)\n// after\nleft := beam.ParDo(s, &extractKeyFn{}, raw)\nif !left.IsValid() { return errors.New(\"left join side missing\") }\nbeam.CoGroupByKey(s, left, right)","handlingStrategy":"validation","validationCode":"for i, c := range joinSides {\n    if !c.IsValid() {\n        return fmt.Errorf(\"CoGBK side %d invalid\", i)\n    }\n}","typeGuard":null,"tryCatchPattern":"res, err := beam.TryCoGroupByKey(s, cols...)\nif err != nil {\n    return fmt.Errorf(\"CoGBK failed (check scope ctx in error): %w\", err)\n}","preventionTips":["Verify each join side is produced before CoGroupByKey","Use TryCoGroupByKey to get the scope context on failure","Check for skipped pipeline branches that leave a side unassigned"],"tags":["beam","cogbk","pipeline-construction","validation"],"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"}