{"record":{"id":"fbc7cfb5a8670619","repo":"apache/beam","slug":"invalid-scope-windowing","errorCode":null,"errorMessage":"invalid scope","messagePattern":"invalid scope","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/windowing.go","lineNumber":82,"sourceCode":"\tdelay time.Duration\n}\n\nfunc (m allowedLateness) windowIntoOption() {}\n\n// AllowedLateness configures for how long data may arrive after the end of a window.\nfunc AllowedLateness(delay time.Duration) WindowIntoOption {\n\treturn allowedLateness{delay: delay}\n}\n\n// WindowInto applies the windowing strategy to each element.\nfunc WindowInto(s Scope, ws *window.Fn, col PCollection, opts ...WindowIntoOption) PCollection {\n\treturn Must(TryWindowInto(s, ws, col, opts...))\n}\n\n// TryWindowInto attempts to insert a WindowInto transform.\nfunc TryWindowInto(s Scope, wfn *window.Fn, col PCollection, opts ...WindowIntoOption) (PCollection, error) {\n\tif !s.IsValid() {\n\t\treturn PCollection{}, errors.New(\"invalid scope\")\n\t}\n\tif !col.IsValid() {\n\t\treturn PCollection{}, errors.New(\"invalid input pcollection\")\n\t}\n\tws := window.WindowingStrategy{Fn: wfn, Trigger: trigger.DefaultTrigger{}}\n\tfor _, opt := range opts {\n\t\tswitch opt := opt.(type) {\n\t\tcase windowTrigger:\n\t\t\t// TODO(BEAM-3304): call validation on trigger construction here\n\t\t\t// so local errors can be returned to the user in their pipeline\n\t\t\t// context instead of at pipeline translation time.\n\t\t\tws.Trigger = opt.trigger\n\t\tcase accumulationMode:\n\t\t\tws.AccumulationMode = opt.mode\n\t\tcase allowedLateness:\n\t\t\tws.AllowedLateness = int(opt.delay / time.Millisecond)\n\t\tdefault:\n\t\t\tpanic(fmt.Sprintf(\"Unknown WindowInto option type: %T: %v\", opt, opt))","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/windowing.go#L64-L100","documentation":"beam.TryWindowInto (and its Must wrapper WindowInto) assigns a windowing strategy to a PCollection. This error is returned when the supplied Scope is invalid — the zero beam.Scope not derived from a pipeline — since the WindowInto transform has no valid scope to attach to. It mirrors the identical check in validate().","triggerScenarios":"Calling beam.TryWindowInto(s, window.FixedWindows(d), col) or beam.WindowInto(...) with s being a zero-value beam.Scope (never initialized from p.Root()), so s.IsValid() is false.","commonSituations":"Helper functions that accept beam.Scope receiving an uninitialized value; scopes built before beam.NewPipeline(); refactoring windowing logic into a struct storing beam.Scope by value that was never set.","solutions":["Initialize the scope from the pipeline: s := p.Root().Scope(\"windowing\") before calling WindowInto.","Verify all constructors/struct fields that store the Scope are actually populated before use.","Use TryWindowInto and check err to get the failure as a value rather than a panic from the Must wrapper.","Add an early `if !s.IsValid() { return col, errors.New(...) }` guard in shared helpers to fail with clearer context."],"exampleFix":"// before\nvar s beam.Scope\nbeam.WindowInto(s, window.FixedWindows(time.Minute), col) // panic: invalid scope\n\n// after\ns := p.Root().Scope(\"windowing\")\nbeam.WindowInto(s, window.FixedWindows(time.Minute), col)","handlingStrategy":"validation","validationCode":"if !s.IsValid() {\n    return fmt.Errorf(\"windowing requires a scope from beam.NewPipeline().Root()\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Initialize scopes from p.Root() before any windowing call.","Prefer TryWindowInto in library code to surface scope problems as errors, not panics.","Keep scope creation adjacent to transform usage to avoid stale or uninitialized scopes."],"tags":["apache-beam","go","windowing","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"}