{"record":{"id":"7de4995c03f83491","repo":"apache/beam","slug":"tried-converting-invalid-pcollection","errorCode":null,"errorMessage":"tried converting invalid PCollection","messagePattern":"tried converting invalid PCollection","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/xlang.go","lineNumber":223,"sourceCode":"\n\t// Expand the transform into ext.Expanded.\n\tif err := xlangx.Expand(edge, &ext); err != nil {\n\t\treturn nil, errors.WithContext(err, \"expanding external transform\")\n\t}\n\n\t// Ensures the expected named outputs are present\n\tgraphx.VerifyNamedOutputs(&ext)\n\t// Using the expanded outputs, the graph's counterpart outputs are updated with bounded values\n\tgraphx.ResolveOutputIsBounded(edge, isBoundedUpdater)\n\n\treturn mapNodeToPCollection(graphx.ExternalOutputs(edge)), nil\n}\n\n// Wrapper functions to handle beam <-> graph boundaries\n\nfunc pCollectionToNode(p PCollection) *graph.Node {\n\tif !p.IsValid() {\n\t\tpanic(\"tried converting invalid PCollection\")\n\t}\n\treturn p.n\n}\n\nfunc nodeToPCollection(n *graph.Node) PCollection {\n\tif n == nil {\n\t\tpanic(\"tried converting invalid Node\")\n\t}\n\tc := PCollection{n}\n\tc.SetCoder(NewCoder(c.Type()))\n\treturn c\n}\n\nfunc mapPCollectionToNode(pMap map[string]PCollection) map[string]*graph.Node {\n\tif pMap == nil {\n\t\treturn nil\n\t}\n","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/xlang.go#L205-L241","documentation":"pCollectionToNode unwraps a beam.PCollection to its internal graph node for cross-language transform mapping, and panics if the PCollection is invalid (its underlying node is unset). An invalid PCollection usually results from using the zero value of PCollection or one produced by a failed/aborted construction path instead of a real pipeline output.","triggerScenarios":"Calling xlang functions (mapPCollectionToNode via CrossLanguage/TryCrossLanguage) with a PCollection that fails IsValid() — passing a zero-value PCollection, a PCollection from a pipeline that errored during construction, or mixing PCollections between different scope/pipeline instances.","commonSituations":"Building cross-language transforms with placeholder/empty PCollections; ignoring an earlier error from a transform that returned an invalid PCollection; accidentally declaring PCollection variables without initialization and passing them to xlang helpers.","solutions":["Call p.IsValid() on every input PCollection before passing it to CrossLanguage/TryCrossLanguage.","Ensure all PCollections originate from real transforms on the same pipeline, not zero values.","Check earlier in the pipeline construction for ignored errors that produced the invalid PCollection.","If shuffling PCollections across pipelines/scopes, rebuild them within the target scope instead of reusing handles."],"exampleFix":"// before\nvar col beam.PCollection\nouts := beam.CrossLanguage(s, urn, payload, addr, map[string]beam.PCollection{\"in\": col}, nil) // panics\n// after\nif !col.IsValid() {\n    return errors.New(\"input PCollection is invalid\")\n}\nouts := beam.CrossLanguage(s, urn, payload, addr, map[string]beam.PCollection{\"in\": col}, nil)","handlingStrategy":"validation","validationCode":"// check every PCollection before cross-language calls\nfor name, col := range inputs {\n    if !col.IsValid() {\n        return fmt.Errorf(\"input %q is an invalid PCollection\", name)\n    }\n}","typeGuard":"func validPCollection(p beam.PCollection) bool {\n    return p.IsValid()\n}","tryCatchPattern":"func toNodeSafe(p beam.PCollection) (n *graph.Node, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"pcollection conversion failed: %v\", r)\n        }\n    }()\n    if !p.IsValid() {\n        return nil, errors.New(\"invalid PCollection\")\n    }\n    return pCollectionToNode(p), nil\n}","preventionTips":["Always obtain PCollections from transform outputs, never declare zero-value PCollection variables.","Call IsValid() on inputs before any xlang helper.","Handle construction errors from earlier transforms instead of passing their results onward.","Do not reuse PCollection handles across different pipelines or scopes."],"tags":["go","apache-beam","cross-language","invalid-pcollection"],"backgroundTag":"internal-invariant-violation","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"}