apache/beam · error
Beam has not been initialized. Call beam.Init() before…
Error message
Beam has not been initialized. Call beam.Init() before pipeline construction.
What it means
The Dataflow runner requires beam.Init() to have been called so flags (project, region, staging location, etc.) are parsed and the environment is configured. Execute panics immediately if beam.Initialized() is false, because building and submitting a job without that configuration cannot proceed safely.
Solutions
- Call beam.Init() (which parses flags) at the start of main before building the pipeline
- Ensure flag.Parse() runs — beam.Init uses the standard flag package
- In tests, call beam.Init() in TestMain or skip Dataflow-dependent tests
- Run the pipeline via beam.Run(ctx, runner, p) after initialization rather than invoking dataflow.Execute directly
Example fix
// before
func main() {
p := beam.NewPipeline()
dataflow.Execute(ctx, p)
}
// after
func main() {
beam.Init()
p := beam.NewPipeline()
beam.Run(ctx, "dataflow", p)
} Defensive patterns
Strategy: validation
Validate before calling
if !beam.Initialized() {
beam.Init()
} Try / catch
func runDataflow(ctx context.Context, p *beam.Pipeline) (pr beam.PipelineResult, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("dataflow execute panicked: %v", r)
}
}()
if !beam.Initialized() { beam.Init() }
return dataflow.Execute(ctx, p)
} Prevention
- Always call beam.Init() as the first statement in main
- Never invoke runner Execute functions directly; use beam.Run
- In tests, call beam.Init() from TestMain
- Wrap pipeline construction so it only happens after flag parsing
When it happens
Trigger: Constructing a beam.NewPipeline() and running it with the Dataflow runner without ever calling beam.Init() (typically from the main function before flag.Parse).
Common situations: New Go Beam users wiring pipelines in tests or libraries where beam.Init() lives in main() that never runs, or calling dataflow.Execute directly instead of through beam.Run after flag parsing.
Related errors
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/54a082e8f58358f8.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/runners/dataflow/dataflow.go:197
}
var unique int32
// Helper function finding first non empty string. Used for handling alias options.
func firstNonEmpty(values ...*string) *string {
for _, value := range values {
if *value != "" {
return value
}
}
return values[0]
}
// Execute runs the given pipeline on Google Cloud Dataflow. It uses the
// default application credentials to submit the job.
func Execute(ctx context.Context, p *beam.Pipeline) (beam.PipelineResult, error) {
if !beam.Initialized() {
panic("Beam has not been initialized. Call beam.Init() before pipeline construction.")
}
edges, nodes, err := p.Build()
if err != nil {
return nil, err
}
streaming := !graph.Bounded(nodes)
beam.PipelineOptions.LoadOptionsFromFlags(flagFilter)
opts, err := getJobOptions(ctx, streaming)
if err != nil {
return nil, err
}
// (1) Build and submit
// NOTE(herohde) 10/8/2018: the last segment of the names must be "worker".
id := fmt.Sprintf("go-%v-%v", atomic.AddInt32(&unique, 1), time.Now().UnixNano())
View on GitHub (pinned to 12126d8942)