{"record":{"id":"538275217e1b52d7","repo":"apache/beam","slug":"failed-to-stat-v","errorCode":null,"errorMessage":"failed to stat %v","messagePattern":"failed to stat (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/artifact/materialize.go","lineNumber":223,"sourceCode":"\tdep            *pipepb.ArtifactInformation\n\texpectedSha256 string\n}\n\nfunc (a artifact) retrieve(ctx context.Context, dest string) error {\n\tpath, err := extractStagingToPath(a.dep)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tfilename := filepath.Join(dest, filepath.FromSlash(path))\n\n\t_, err = os.Stat(filename)\n\tif err == nil {\n\t\tif err = os.Remove(filename); err != nil {\n\t\t\treturn errors.Errorf(\"failed to delete: %v (remove: %v)\", filename, err)\n\t\t}\n\t} else if !os.IsNotExist(err) {\n\t\treturn errors.Wrapf(err, \"failed to stat %v\", filename)\n\t}\n\n\tif err := os.MkdirAll(filepath.Dir(filename), os.ModePerm); err != nil {\n\t\treturn err\n\t}\n\n\tstream, err := a.client.GetArtifact(ctx, &jobpb.GetArtifactRequest{Artifact: a.dep})\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tfd, err := os.OpenFile(filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0755)\n\tif err != nil {\n\t\treturn err\n\t}\n\tw := bufio.NewWriter(fd)\n\n\tsha256Hash, err := writeChunks(stream, w)","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/artifact/materialize.go#L205-L241","documentation":"Returned by artifact.retrieve when os.Stat on the destination file fails with an error other than \"not exist\" (wrapf context: \"failed to stat <filename>\"). Before re-downloading, the library stats the target to decide whether to delete it; any stat failure other than IsNotExist aborts retrieval.","triggerScenarios":"os.Stat returning errors like EACCES (no search permission on a path component), ENOTDIR (a path component is a file), ELOOP (symlink loop), or device errors — anything that is not os.ErrNotExist.","commonSituations":"A parent directory in dest lacks execute permission for the running user; a previously retrieved artifact file shares a name with a required subdirectory (path component is a file); broken mount or dangling symlink setup inside the dest tree.","solutions":["Check permissions on every path component of dest so the process can traverse it (chmod +x on directories).","Remove conflicting entries where a file occupies a path that must be a directory.","Use a clean, dedicated artifact staging directory for each run to avoid stale/odd trees.","Inspect the wrapped error in the message to identify the exact failing path component."],"exampleFix":"// before: nested, partially unwritable dest\nartifact.Materialize(ctx, endpoint, deps, rt, \"/srv/jobs/user/abc/artifacts\")\n// after: ensure dest exists and is traversable/writable\nos.MkdirAll(\"/srv/jobs/user/abc/artifacts\", 0o755)\nartifact.Materialize(ctx, endpoint, deps, rt, \"/srv/jobs/user/abc/artifacts\")","handlingStrategy":"validation","validationCode":"func canTraverse(dest string) error {\n\tfor p := dest; p != \"/\" && p != \".\"; p = filepath.Dir(p) {\n\t\tif info, err := os.Stat(p); err != nil {\n\t\t\treturn err\n\t\t} else if !info.IsDir() {\n\t\t\treturn fmt.Errorf(\"%s is a file, not a directory\", p)\n\t\t}\n\t}\n\treturn nil\n}\n// call canTraverse(dest) before Materialize","typeGuard":null,"tryCatchPattern":"if err := artifact.Materialize(ctx, endpoint, deps, rt, dest); err != nil {\n\tif strings.Contains(err.Error(), \"failed to stat\") {\n\t\treturn fmt.Errorf(\"dest tree not traversable: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Pre-create dest with os.MkdirAll(dest, 0o755) and ensure +x on all parent dirs.","Avoid stale trees where files occupy paths that should be directories.","Run workers under a user that owns or can traverse the artifact directory.","Use clean per-run directories to avoid odd symlink/permission residue."],"tags":["go","filesystem","stat","beam-artifacts"],"backgroundTag":"file-read-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"}