{"record":{"id":"5478ec1c6fc379c1","repo":"apache/beam","slug":"could-not-detect-user-main","errorCode":null,"errorMessage":"could not detect user main","messagePattern":"could not detect user main","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/runners/universal/runnerlib/compile.go","lineNumber":84,"sourceCode":"//\t  /Users/herohde/go/src/github.com/apache/beam/sdks/go/pkg/beam/runners/beamexec/main.go (skip: 2)\n//\t* /Users/herohde/go/src/github.com/apache/beam/sdks/go/examples/wordcount/wordcount.go (skip: 3)\n//\t  /usr/local/go/src/runtime/proc.go (skip: 4)      // not always present\n//\t  /usr/local/go/src/runtime/asm_amd64.s (skip: 4 or 5)\nfunc buildWorkerBinary(ctx context.Context, filename string, opts CompileOpts) error {\n\tprogram := \"\"\n\tvar isTest bool\n\tfor i := 3; ; i++ {\n\t\t_, file, _, ok := runtime.Caller(i)\n\t\tif !ok || !strings.HasSuffix(file, \".go\") || strings.HasSuffix(file, \"runtime/proc.go\") {\n\t\t\tbreak\n\t\t} else if strings.HasSuffix(file, \"testing/testing.go\") {\n\t\t\tisTest = true\n\t\t\tbreak\n\t\t}\n\t\tprogram = file\n\t}\n\tif !strings.HasSuffix(program, \".go\") {\n\t\treturn errors.New(\"could not detect user main\")\n\t}\n\tgoos := \"linux\"\n\tgoarch := \"amd64\"\n\n\tif opts.OS != \"\" {\n\t\tgoos = opts.OS\n\t}\n\tif opts.Arch != \"\" {\n\t\tgoarch = opts.Arch\n\t}\n\n\tcgo := \"0\"\n\n\tlog.Infof(ctx, \"Cross-compiling %v with GOOS=%s GOARCH=%s CGO_ENABLED=%s as %v\", program, goos, goarch, cgo, filename)\n\n\t// Cross-compile given go program. Not awesome.\n\tprogram = program[:strings.LastIndex(program, \"/\")+1]\n\tprogram = program + \".\"","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/runners/universal/runnerlib/compile.go#L66-L102","documentation":"When the universal runner stages a job it must compile a worker binary, which requires locating the user's main package file. buildWorkerBinary walks the candidate files and sets `program`; if after the search `program` does not end with '.go', no user main was found and this error is returned. It means Beam could not determine which Go file holds the pipeline entry point to cross-compile.","triggerScenarios":"Calling universal runner's BuildTempWorkerBinary / running on remote runners (Dataflow, Flink, Spark) with a program path that is not a .go file, an empty program, or a directory of files where none was identified as the main.","commonSituations":"Cross-compiling pipelines where --worker_binary or the main package path is misconfigured; running compiled test binaries; submitting jobs from modules whose main package is not discoverable.","solutions":["Ensure the pipeline is submitted with a path to the Go file containing func main() (package main)","Run `go build` locally first to confirm the main package compiles and is locatable","Pass an explicit pre-built worker binary via --worker_binary to skip source detection","Check opts.WorkingDir/env so the file scan actually reaches your .go files"],"exampleFix":"// before\nbeamx.Run(ctx, p) // in a file without package main\n// after\n// ensure cmd/pipeline/main.go declares:\npackage main\n\nfunc main() {\n\tbeam.Init()\n\t// ... build and run pipeline\n}","handlingStrategy":"validation","validationCode":"// before submitting, confirm the main file exists and is package main\nfi, err := os.Stat(mainFile)\nif err != nil || fi.IsDir() || !strings.HasSuffix(mainFile, \".go\") {\n\treturn fmt.Errorf(\"main file %q is not a .go source file\", mainFile)\n}","typeGuard":null,"tryCatchPattern":"if _, err := runnerlib.BuildTempWorkerBinary(ctx, prog, opts); err != nil {\n\tif strings.Contains(err.Error(), \"could not detect user main\") {\n\t\treturn fmt.Errorf(\"supply --worker_binary or run from a package/main directory: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Run jobs from a directory whose main package contains func main()","Verify `go build ./...` succeeds before remote submission","Pass an explicit --worker_binary when source layout is nonstandard"],"tags":["go","beam","universal-runner","compilation"],"backgroundTag":"file-not-found","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}