{"record":{"id":"e37b0ff46ec73954","repo":"apache/beam","slug":"beam-has-not-been-initialized-call-beam-init-before-pipeline-e37b0f","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":"critical","filePath":"sdks/go/pkg/beam/runners/universal/universal.go","lineNumber":48,"sourceCode":"\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/internal/errors\"\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/log\"\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/options/jobopts\"\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/runners/universal/extworker\"\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/runners/universal/runnerlib\"\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/runners/vet\"\n)\n\nfunc init() {\n\t// Note that we also _ import harness/init to setup the remote execution hook.\n\tbeam.RegisterRunner(\"universal\", Execute)\n\tbeam.RegisterRunner(\"PortableRunner\", Execute)\n\tbeam.RegisterRunner(\"portable\", Execute)\n}\n\n// Execute executes the pipeline on a universal beam runner.\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\tif *jobopts.Strict {\n\t\tlog.Info(ctx, \"Strict mode enabled, applying additional validation.\")\n\t\tif _, err := vet.Execute(ctx, p); err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"strictness check failed\")\n\t\t}\n\t\tlog.Info(ctx, \"Strict mode validation passed.\")\n\t}\n\n\tendpoint, err := jobopts.GetEndpoint()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tedges, _, err := p.Build()\n\tif err != nil {\n\t\treturn nil, err","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/runners/universal/universal.go#L30-L66","documentation":"beam.Execute for the universal runner requires global SDK initialization (flags, job options, logging) performed by beam.Init(). If the program builds a pipeline and calls Execute before Init, the runner panics because job option flags and registration would be unset.","triggerScenarios":"Calling universal.Execute (or running with --runner=portable) after constructing a pipeline but without ever calling beam.Init(); calling Execute in init() ordering contexts where beam.Init() hasn't run.","commonSituations":"Go binaries that parse flags late or use custom flag parsing and skip beam.Init(); test helpers that build pipelines at package init time; copying example code that omitted beam.Init().","solutions":["Call beam.Init() at the start of main(), before any pipeline construction or runner execution.","Ensure beam.Init() runs after flag definitions but before flag.Parse-driven option consumption; place it before Execute.","If using custom flags, still call beam.Init() (it parses Beam's job-option flags) or set job options explicitly.","Restructure code that builds pipelines in package init() to defer building until after beam.Init() in main."],"exampleFix":"// before\nfunc main() {\n    p := beam.NewPipeline()\n    beam.Run(ctx, \"portable\", p) // panics: not initialized\n}\n// after\nfunc main() {\n    beam.Init()\n    p := beam.NewPipeline()\n    beam.Run(ctx, \"portable\", p)\n}","handlingStrategy":"validation","validationCode":"if !beam.Initialized() { beam.Init() } // before Execute/pipeline construction","typeGuard":null,"tryCatchPattern":"defer func(){ if r := recover(); r != nil && strings.Contains(fmt.Sprint(r), \"Beam has not been initialized\") { /* re-run with beam.Init() first */ } }()","preventionTips":["Always call beam.Init() at the top of main()","Don't build pipelines in package init()","Keep standard flag parsing so Beam job-option flags are registered"],"tags":["go","apache-beam","initialization","universal-runner"],"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"}