{"record":{"id":"66dbe171651d4d11","repo":"apache/beam","slug":"failed-to-open-file-s","errorCode":null,"errorMessage":"failed to open file %s","messagePattern":"failed to open file (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/runners/dataflow/dataflowlib/stage.go","lineNumber":42,"sourceCode":"\t\"os\"\n\n\t\"cloud.google.com/go/storage\"\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph\"\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime/xlangx\"\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/internal/errors\"\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/util/gcsx\"\n)\n\n// StageModel uploads the pipeline model to GCS as a unique object.\nfunc StageModel(ctx context.Context, project, modelURL string, model []byte) error {\n\treturn upload(ctx, project, modelURL, bytes.NewReader(model))\n}\n\n// stageFile uploads a file to GCS, and returns the sha256 hash.\nfunc stageFile(ctx context.Context, project, url, filename string) (string, error) {\n\tfd, err := os.Open(filename)\n\tif err != nil {\n\t\treturn \"\", errors.Wrapf(err, \"failed to open file %s\", filename)\n\t}\n\tdefer fd.Close()\n\n\tsha256W := sha256.New()\n\ttee := io.TeeReader(fd, sha256W)\n\tif err := upload(ctx, project, url, tee); err != nil {\n\t\treturn \"\", err\n\t}\n\thash := hex.EncodeToString(sha256W.Sum(nil))\n\treturn hash, nil\n}\n\nfunc upload(ctx context.Context, project, object string, r io.Reader) error {\n\tbucket, obj, err := gcsx.ParseObject(object)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"invalid staging location %v\", object)\n\t}\n\tclient, err := gcsx.NewClient(ctx, storage.ScopeReadWrite)","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/runners/dataflow/dataflowlib/stage.go#L24-L60","documentation":"stageFile in the Dataflow runner's staging library opens the local file to be uploaded (a worker binary or artifact) before pushing it to GCS. If os.Open fails, the upload aborts and the os error is wrapped with the filename for context. This means the pipeline could not even read the artifact it needs to stage to GCS before the job is submitted.","triggerScenarios":"Calling stageFile (via StageModel or Execute/ResolveXLangArtifacts) with a filename that does not exist, is a directory, or is not readable by the current process. os.Open returns the underlying error which is wrapped here.","commonSituations":"Running a Dataflow pipeline with --worker_binary or an XLang artifact path that is wrong relative to the current working directory; the binary was never built; a path is passed without escaping spaces; running under a service account or container lacking read permission on the file.","solutions":["Verify the filename exists and is a regular readable file before submitting: os.Stat(filename) and check err == nil and !info.IsDir().","If passing a worker binary, build it first (go build) and pass the absolute path.","Check file permissions (chmod/chown) and that the process user can read the path.","Check the wrapped inner error in the message: 'no such file or directory' means wrong path, 'permission denied' means fix ACLs."],"exampleFix":"// before\nhash, err := stageFile(ctx, project, url, \"worker/beamapp\")\n// after\nabs, _ := filepath.Abs(\"worker/beamapp\")\nif _, err := os.Stat(abs); err != nil {\n    log.Fatalf(\"worker binary not found at %s: build it first\", abs)\n}\nhash, err := stageFile(ctx, project, url, abs)","handlingStrategy":"validation","validationCode":"info, err := os.Stat(filename)\nif err != nil {\n    return fmt.Errorf(\"staging artifact %s not accessible: %w\", filename, err)\n}\nif info.IsDir() {\n    return fmt.Errorf(\"%s is a directory, expected a file\", filename)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always build and verify worker binaries exist before submitting Dataflow jobs.","Use absolute paths for staging artifacts.","Stat-check all artifact paths as a pre-submit step in CI."],"tags":["go","gcp","dataflow","file-io","staging"],"backgroundTag":"file-open-failed","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"}