{"record":{"id":"71b56c09000174b7","repo":"apache/beam","slug":"invalid-pcollection-71b56c","errorCode":null,"errorMessage":"Invalid PCollection","messagePattern":"Invalid PCollection","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/pcollection.go","lineNumber":58,"sourceCode":"type PCollection struct {\n\t// n is the graph node that PCollection wraps. If there is no node, the\n\t// PCollection is invalid.\n\tn *graph.Node\n}\n\n// IsValid returns true iff the PCollection is valid and part of a Pipeline.\n// Any use of an invalid PCollection will result in a panic.\nfunc (p PCollection) IsValid() bool {\n\treturn p.n != nil\n}\n\n// TODO(herohde) 5/30/2017: add name for PCollections? Java supports it.\n\n// Type returns the full type 'A' of the elements. 'A' must be a concrete\n// type, such as int or KV<int,string>.\nfunc (p PCollection) Type() FullType {\n\tif !p.IsValid() {\n\t\tpanic(\"Invalid PCollection\")\n\t}\n\treturn p.n.Type()\n}\n\n// Coder returns the coder for the collection. The Coder is of type 'A'.\nfunc (p PCollection) Coder() Coder {\n\tif !p.IsValid() {\n\t\tpanic(\"Invalid PCollection\")\n\t}\n\treturn Coder{p.n.Coder}\n}\n\n// SetCoder set the coder for the collection. The Coder must be of type 'A'.\nfunc (p PCollection) SetCoder(c Coder) error {\n\tif !p.IsValid() {\n\t\tpanic(\"Invalid PCollection\")\n\t}\n","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/pcollection.go#L40-L76","documentation":"PCollection.Type returns the full element type of the collection. Because PCollection is a lightweight wrapper, calling Type on a zero-value or unset PCollection is invalid, so the library panics with \"Invalid PCollection\" rather than dereferencing a nil node.","triggerScenarios":"Calling .Type() on a zero-value PCollection (var p beam.PCollection), on a PCollection from a failed/unchecked TryParDo or TryCoGBK result, or one returned by an API whose error was ignored.","commonSituations":"Ignoring the error from Try* variants (which return empty PCollections on failure) and immediately calling .Type(); storing PCollections in structs initialized without values; out-of-range indexing into a returned slice producing an invalid wrapper.","solutions":["Check p.IsValid() before calling Type, or ensure the PCollection comes from a Must*-style API (e.g. ParDo, Impulse) that cannot return an invalid value.","Handle the error return of TryParDo/TryCoGBK/TryReshuffle etc. before using the returned PCollections.","Audit code paths where a PCollection variable is assigned conditionally and may remain the zero value."],"exampleFix":"// before\nret, err := beam.TryParDo(s, &fn{}, col)\n_ = err\nt := ret[0].Type() // panics: Invalid PCollection\n\n// after\nret, err := beam.TryParDo(s, &fn{}, col)\nif err != nil {\n    log.Fatal(err)\n}\nt := ret[0].Type()","handlingStrategy":"validation","validationCode":"if !p.IsValid() {\n    return errors.New(\"PCollection is invalid; a Try* call likely failed\")\n}\nt := p.Type()","typeGuard":null,"tryCatchPattern":"defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"invalid PCollection access: %v\", r) } }()","preventionTips":["Always check errors from TryParDo/TryCoGBK/TryReshuffle before using results","Prefer Must*-style APIs when you want construction failures to fail fast","Never index result slices without bounds checks"],"tags":["go","apache-beam","pcollection","panic","invalid-state"],"backgroundTag":"invalid-state-transition","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"}