{"record":{"id":"4c163fafe68f883b","repo":"apache/beam","slug":"invalid-scope-gbk","errorCode":null,"errorMessage":"invalid scope","messagePattern":"invalid scope","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/gbk.go","lineNumber":74,"sourceCode":"// an error on failure.\nfunc TryGroupByKey(s Scope, a PCollection) (PCollection, error) {\n\treturn TryCoGroupByKey(s, a)\n}\n\n// CoGroupByKey inserts a CoGBK transform into the pipeline.\nfunc CoGroupByKey(s Scope, cols ...PCollection) PCollection {\n\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","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/gbk.go#L56-L92","documentation":"TryCoGroupByKey (used by TryGroupByKey and CoGroupByKey) validates the Scope before inserting a CoGBK transform into the pipeline graph. If the scope is invalid (zero value or from a failed construction), the transform cannot be attached, so the error is returned wrapped with additional CoGBK context naming the scope.","triggerScenarios":"beam.CoGroupByKey(s, cols...) or beam.TryCoGroupByKey(s, cols...) / TryGroupByKey where s is a zero-value Scope{}, a Scope obtained from an errored call, or a scope whose parent pipeline was not created via beam.NewPipeline().","commonSituations":"Reusing a Scope captured from another pipeline; passing a Scope struct member that was never assigned; ignoring an earlier error that returned PCollection{} with an invalid embedded scope and then trying to group it.","solutions":["Pass a valid scope from beam.NewPipeline() or a child scope created via beam.Scope(\"label\") as the first argument.","Check s.IsValid() before calling; if false, retrace scope creation in your code.","Verify you are not mixing PCollections/scopes from two different pipelines — build all inputs within the same pipeline."],"exampleFix":"// before\nvar s beam.Scope\nres := beam.CoGroupByKey(s, a, b) // invalid scope\n\n// after\np := beam.NewPipeline()\nres := beam.CoGroupByKey(p, a, b)","handlingStrategy":"validation","validationCode":"if !s.IsValid() {\n\treturn fmt.Errorf(\"cannot CoGroupByKey: invalid scope %v\", s)\n}\nout := beam.CoGroupByKey(s, cols...)","typeGuard":"func validScope(s beam.Scope) bool { return s.IsValid() }","tryCatchPattern":null,"preventionTips":["Create all scopes from a single beam.NewPipeline() to avoid invalid or cross-pipeline scopes.","Validate scope validity in pipeline-construction helpers.","Do not persist or copy Scope values across pipeline lifetimes."],"tags":["go","apache-beam","cogroupbykey","invalid-scope"],"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-14T16:17:12.679Z"}