apache/beam · error
window must not be nil
Error message
window must not be nil
What it means
NewW in sdks/go/pkg/beam/core/graph/coder/coder.go panics with "window must not be nil" when the WindowCoder argument for a WindowedValue coder is nil. A WindowedValue coder must record how windows themselves are encoded, so a nil window coder is invalid and triggers a fail-fast panic instead of producing an unmarshalable coder.
Source
Thrown at sdks/go/pkg/beam/core/graph/coder/coder.go:416
}
// IsW returns true iff the coder is for a WindowedValue.
func IsW(c *Coder) bool {
return c.Kind == WindowedValue
}
// NewPI returns a PaneInfo coder
func NewPI() *Coder {
return &Coder{Kind: PaneInfo, T: typex.New(typex.PaneInfoType)}
}
// NewW returns a WindowedValue coder for the window of elements.
func NewW(c *Coder, w *WindowCoder) *Coder {
if c == nil {
panic("coder must not be nil")
}
if w == nil {
panic("window must not be nil")
}
return &Coder{
Kind: WindowedValue,
T: typex.NewW(c.T),
Window: w,
Components: []*Coder{c},
}
}
// NewPW returns a ParamWindowedValue coder for the window of elements.
func NewPW(c *Coder, w *WindowCoder) *Coder {
if c == nil {
panic("coder must not be nil")
}
if w == nil {
panic("window must not be nil")
}View on GitHub (pinned to 12126d8942)
Solutions
- Pass an explicit window coder such as coder.NewGlobalWindow() or coder.NewIntervalWindowCoder().
- Check the origin of the *WindowCoder for nil-returning error paths and propagate the error.
- Initialize window coders in a shared helper that never returns nil.
Example fix
// before wc := coder.NewW(c, nil) // panics // after wc := coder.NewW(c, coder.NewGlobalWindow())
Defensive patterns
Strategy: validation
Validate before calling
if w == nil {
w = coder.NewGlobalWindow() // or return an error
}
wc := coder.NewW(c, w) Type guard
func hasWindowCoder(w *coder.WindowCoder) bool { return w != nil } Try / catch
func newWSafe(c *coder.Coder, w *coder.WindowCoder) (wc *coder.Coder, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("NewW failed: %v", r)
}
}()
return coder.NewW(c, w), nil
} Prevention
- Default to coder.NewGlobalWindow() when no windowing strategy is configured.
- Handle errors from window-coder constructors instead of passing nil through.
- Store window coders in package-level helpers so call sites get valid defaults.
When it happens
Trigger: Calling coder.NewW(c, nil), typically when the *WindowCoder variable was never assigned or a constructor returning (*WindowCoder, error) returned nil and the error was ignored.
Common situations: Custom windowing pipelines where a window coder was assumed but never created; test code copying coder setups and dropping the window argument.
Related errors
- unwindowed coder %v on DataSource %v: %v
- could not unmarshal window coder for pcollection %v: %w
- unwindowed coder %v on DataSink %v: %v
- could not unmarshal window coder for timer: %w
- could not unmarshal global window coder: %w
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/b2bbc4bf63266d24.
Report an issue: GitHub.