{"record":{"id":"54a082e8f58358f8","repo":"apache/beam","slug":"beam-has-not-been-initialized-call-beam-init-before-pipeline","errorCode":null,"errorMessage":"Beam has not been initialized. Call beam.Init() before pipeline construction.","messagePattern":"Beam has not been initialized\\. Call beam\\.Init\\(\\) before pipeline construction\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/runners/dataflow/dataflow.go","lineNumber":197,"sourceCode":"}\n\nvar unique int32\n\n// Helper function finding first non empty string. Used for handling alias options.\nfunc firstNonEmpty(values ...*string) *string {\n\tfor _, value := range values {\n\t\tif *value != \"\" {\n\t\t\treturn value\n\t\t}\n\t}\n\treturn values[0]\n}\n\n// Execute runs the given pipeline on Google Cloud Dataflow. It uses the\n// default application credentials to submit the job.\nfunc Execute(ctx context.Context, p *beam.Pipeline) (beam.PipelineResult, error) {\n\tif !beam.Initialized() {\n\t\tpanic(\"Beam has not been initialized. Call beam.Init() before pipeline construction.\")\n\t}\n\n\tedges, nodes, err := p.Build()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tstreaming := !graph.Bounded(nodes)\n\n\tbeam.PipelineOptions.LoadOptionsFromFlags(flagFilter)\n\topts, err := getJobOptions(ctx, streaming)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// (1) Build and submit\n\t// NOTE(herohde) 10/8/2018: the last segment of the names must be \"worker\".\n\tid := fmt.Sprintf(\"go-%v-%v\", atomic.AddInt32(&unique, 1), time.Now().UnixNano())\n","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/runners/dataflow/dataflow.go#L179-L215","documentation":"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.","triggerScenarios":"Constructing a beam.NewPipeline() and running it with the Dataflow runner without ever calling beam.Init() (typically from the main function before flag.Parse).","commonSituations":"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.","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"],"exampleFix":"// before\nfunc main() {\n    p := beam.NewPipeline()\n    dataflow.Execute(ctx, p)\n}\n// after\nfunc main() {\n    beam.Init()\n    p := beam.NewPipeline()\n    beam.Run(ctx, \"dataflow\", p)\n}","handlingStrategy":"validation","validationCode":"if !beam.Initialized() {\n    beam.Init()\n}","typeGuard":null,"tryCatchPattern":"func runDataflow(ctx context.Context, p *beam.Pipeline) (pr beam.PipelineResult, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"dataflow execute panicked: %v\", r)\n        }\n    }()\n    if !beam.Initialized() { beam.Init() }\n    return dataflow.Execute(ctx, p)\n}","preventionTips":["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"],"tags":["go","dataflow","initialization"],"backgroundTag":"missing-configuration","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"}