{"record":{"id":"9bbc1870510b3a8a","repo":"apache/beam","slug":"invalid-main-pcollection","errorCode":null,"errorMessage":"invalid main pcollection","messagePattern":"invalid main pcollection","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/validate.go","lineNumber":53,"sourceCode":"\n// ValidateNonCompositeType panics if the type of the PCollection is not a\n// composite type. It returns the type.\nfunc ValidateNonCompositeType(col PCollection) typex.FullType {\n\tt := col.Type()\n\tif typex.IsComposite(t.Type()) {\n\t\tpanic(fmt.Sprintf(\"pcollection must be of non-composite type: %v\", col))\n\t}\n\treturn t\n}\n\n// validate validates and processes the input collection and options. Private convenience\n// function.\nfunc validate(s Scope, col PCollection, opts []Option) ([]SideInput, map[string]reflect.Type, error) {\n\tif !s.IsValid() {\n\t\treturn nil, nil, errors.New(\"invalid scope\")\n\t}\n\tif !col.IsValid() {\n\t\treturn nil, nil, errors.New(\"invalid main pcollection\")\n\t}\n\tside, defs := parseOpts(opts)\n\tfor i, in := range side {\n\t\tif !in.Input.IsValid() {\n\t\t\treturn nil, nil, errors.Errorf(\"invalid side pcollection: index %v\", i)\n\t\t}\n\t}\n\ttypedefs, err := makeTypedefs(defs)\n\tif err != nil {\n\t\treturn nil, nil, err\n\t}\n\treturn side, typedefs, nil\n}\n\nfunc makeTypedefs(list []TypeDefinition) (map[string]reflect.Type, error) {\n\ttypedefs := make(map[string]reflect.Type)\n\tfor _, v := range list {\n\t\tif !typex.IsUniversal(v.Var) {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/validate.go#L35-L71","documentation":"validate() (used by TryParDo, TryCombinePerKey and related constructors) checks that the main input PCollection is valid before building the transform. This error means col is the zero PCollection — produced when a transform returned an error earlier and the caller ignored it, or when a PCollection variable was never assigned. The pipeline graph cannot reference a non-existent node.","triggerScenarios":"Calling beam.TryParDo(s, dofn, col) / TryCombinePerKey where col is the zero value: typically from `col, _ := someTryTransform(...)` swallowing an earlier error, or `var col beam.PCollection` that was never populated.","commonSituations":"Ignoring the error from Try* transforms and using the returned zero PCollection downstream; conditional branches that skip populating a PCollection; accidental shadowing of a PCollection variable; using the result of a function that returns PCollection{} on a failure path.","solutions":["Handle errors from every Try* call: `out, err := beam.TryParDo(...); if err != nil { return err }` — the zero PCollection almost always traces back to an earlier ignored error.","Audit the variable holding the main input and confirm it is the return value of a successful transform, not a zero value.","Check for shadowed variables (`col :=` vs `col =`) inside if/else blocks.","Switch to Must-style constructors during debugging so the first construction failure panics immediately instead of propagating an invalid PCollection."],"exampleFix":"// before\ncol, _ := beam.TryParDo(s, fn, input) // err swallowed; col invalid downstream\nbeam.ParDo0(s, fn2, col)\n\n// after\ncol, err := beam.TryParDo(s, fn, input)\nif err != nil {\n    return err\n}\nbeam.ParDo0(s, fn2, col)","handlingStrategy":"validation","validationCode":"if !col.IsValid() {\n    return fmt.Errorf(\"main input PCollection is not initialized; an upstream Try* call likely failed\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never discard the error from Try* transform constructors; check it immediately.","Avoid zero values of beam.PCollection as intermediate variables — always assign from a transform's return.","Watch for variable shadowing inside branches when building pipeline collections."],"tags":["apache-beam","go","pipeline-construction"],"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"}