{"record":{"id":"ae782b72e556cbf7","repo":"apache/beam","slug":"error-opening-destination-file-s-w","errorCode":null,"errorMessage":"error opening destination file %s: %w","messagePattern":"error opening destination file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go","lineNumber":182,"sourceCode":"\tfor _, file := range reader.File {\n\t\tfileName, err := validatePath(dest, file.Name)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error validating file path (%s, %s): %w\", dest, file.Name, err)\n\t\t}\n\t\tif file.FileInfo().IsDir() {\n\t\t\tos.MkdirAll(fileName, 0700)\n\t\t\tcontinue\n\t\t}\n\n\t\tsf, err := file.Open()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error opening source file %s: %w\", file.Name, err)\n\t\t}\n\t\tdefer sf.Close()\n\n\t\tdf, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0777)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error opening destination file %s: %w\", fileName, err)\n\t\t}\n\t\tdefer df.Close()\n\n\t\tif _, err := io.Copy(df, sf); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc packJar(source, dest string) error {\n\tjar, err := os.Create(dest)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error creating jar packJar(%s,%s)=%w\", source, dest, err)\n\t}\n\tdefer jar.Close()\n\n\tjarFile := zip.NewWriter(jar)","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go#L164-L200","documentation":"During extraction of an Uber JAR (extractJar, called from MakeJar), a file inside the JAR could not be written to the destination directory. os.OpenFile with O_WRONLY|O_CREATE|O_TRUNC failed, typically because the cache directory tree is not writable or a same-named path is a directory. The library wraps the OS error with the destination file name so the failing entry is identifiable.","triggerScenarios":"extractJar(mainJar, tmpDir) walks entries of the source JAR and calls os.OpenFile(fileName, O_WRONLY|O_CREATE|O_TRUNC, 0777) for each non-directory entry; failure occurs when the dest dir lacks write permission, disk is full, a JAR entry name collides with an existing directory on disk, or the path is invalid on the OS.","commonSituations":"Read-only $HOME or full disk when the jar cache (~/.beam661bea09-5dd8-4b9a-ac72-270a895bd3b1 by default) is written; corrupted or adversarially crafted JAR whose entry names collide with directories created earlier in the same extraction; running the expansion service as a non-root container user with an unwritable home.","solutions":["Check that the directory holding the JAR cache (under $HOME/.beam661bea09-.../tmpDir) exists and is writable by the running user (ls -ld, chown/chmod).","Free disk space (df -h) and retry; a full filesystem makes O_CREATE fail with ENOSPC.","If an entry-name/directory collision is suspected, delete the stale tmpDir cache directory and re-run so extraction starts clean.","Verify the JAR is not corrupt (unzip -t mainJar) and that entry names are sane."],"exampleFix":"// before: cache dir owned by root in container\nUSER root\n// after: run the expansion service as a user that owns its home\nRUN mkdir -p /home/beam && chown beam:beam /home/beam\nUSER beam","handlingStrategy":"validation","validationCode":"destDir := filepath.Dir(fileName)\nif info, err := os.Stat(destDir); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"dest dir %s missing: %w\", destDir, err)\n}\nif fi, err := os.Stat(fileName); err == nil && fi.IsDir() {\n    return fmt.Errorf(\"%s exists as a directory; remove collision\", fileName)\n}\nif usable, err := hasFreeSpace(destDir); err == nil && !usable { /* abort */ }","typeGuard":null,"tryCatchPattern":"df, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0777)\nif err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && errors.Is(pe.Err, fs.ErrPermission) {\n        // fix perms / re-run as correct user\n    }\n    return fmt.Errorf(\"error opening destination file %s: %w\", fileName, err)\n}","preventionTips":["Run the process with a writable HOME where the Beam jar cache lives.","Monitor disk space on the volume hosting the cache.","Wipe tmpDir before each MakeJar run to avoid entry/directory collisions.","Validate JARs with unzip -t before extraction."],"tags":["go","filesystem","jar","io"],"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"}