{"record":{"id":"23ae36ca71a1ab17","repo":"apache/beam","slug":"invalid-scope-xlang","errorCode":null,"errorMessage":"invalid scope","messagePattern":"invalid scope","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/xlang.go","lineNumber":181,"sourceCode":"\tnamedOutputs, err := TryCrossLanguage(s, urn, payload, expansionAddr, namedInputs, namedOutputTypes)\n\tif err != nil {\n\t\tpanic(errors.WithContextf(err, \"tried cross-language for %v against %v and failed\", urn, expansionAddr))\n\t}\n\treturn namedOutputs\n}\n\n// TryCrossLanguage coordinates the core functions required to execute the cross-language transform.\n// See CrossLanguage for user documentation.\nfunc TryCrossLanguage(\n\ts Scope,\n\turn string,\n\tpayload []byte,\n\texpansionAddr string,\n\tnamedInputs map[string]PCollection,\n\tnamedOutputTypes map[string]FullType,\n) (map[string]PCollection, error) {\n\tif !s.IsValid() {\n\t\tpanic(errors.New(\"invalid scope\"))\n\t}\n\n\tinputsMap, inboundLinks := graph.NamedInboundLinks(mapPCollectionToNode(namedInputs))\n\toutputsMap, outboundLinks := graph.NamedOutboundLinks(s.real, namedOutputTypes)\n\n\t// Set the coder for outbound links for downstream validation.\n\tfor n, i := range outputsMap {\n\t\tc := NewCoder(namedOutputTypes[n])\n\t\toutboundLinks[i].To.Coder = c.coder\n\t}\n\n\text := graph.ExternalTransform{\n\t\tUrn:           urn,\n\t\tPayload:       payload,\n\t\tExpansionAddr: expansionAddr,\n\t}.WithNamedInputs(inputsMap).WithNamedOutputs(outputsMap)\n\n\t// Adding an edge in the graph corresponding to the ExternalTransform","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/xlang.go#L163-L199","documentation":"beam.TryCrossLanguage expands a cross-language transform via an external expansion service. Unlike the other Try* constructors, an invalid scope here is treated as a programmer-level invariant breach: instead of returning the error it panics with errors.New(\"invalid scope\"). A valid Scope derived from the pipeline is mandatory to attach the external transform node to the graph.","triggerScenarios":"Calling beam.TryCrossLanguage(s, urn, payload, addr, inputs, outputTypes) with a zero beam.Scope (s.IsValid() == false); the panic fires immediately at the entry of the function.","commonSituations":"Building cross-language calls in helpers that receive beam.Scope by value but are handed an uninitialized scope; scopes constructed before beam.NewPipeline(); forgetting that unlike other Try* functions this one panics rather than returns an error, so no recover-friendly error path exists.","solutions":["Pass a real scope: s := p.Root().Scope(\"xlang\") obtained from the same pipeline whose PCollections are in namedInputs.","Recover from panics only at a top-level boundary if you must; the correct fix is initializing the scope, not catching the panic.","Ensure the scope and all named input PCollections come from one pipeline; scopes from a different pipeline can also produce invalid graph state.","Wrap cross-language construction in a helper that checks s.IsValid() first and returns a descriptive error before calling TryCrossLanguage."],"exampleFix":"// before\nvar s beam.Scope\nbeam.CrossLanguage(s, \"beam:transform:xxx:v1\", payload, addr, inputs, outs) // panic\n\n// after\ns := p.Root().Scope(\"external\")\nbeam.CrossLanguage(s, \"beam:transform:xxx:v1\", payload, addr, inputs, outs)","handlingStrategy":"validation","validationCode":"if !s.IsValid() {\n    return fmt.Errorf(\"TryCrossLanguage panics on invalid scope; derive s from beam.NewPipeline().Root()\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Note this API panics instead of returning the error — validate the scope yourself first.","Derive the cross-language scope from the same pipeline that owns the input PCollections.","Centralize xlang expansion calls in one helper with an upfront IsValid check."],"tags":["apache-beam","go","cross-language","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"}