apache/beam · error

error opening file

Error message

error opening file %s: %w

What it means

packJar failed to open a file from the source tree (os.Open(path)) after creating its zip header, so its contents cannot be copied into the JAR. The wrapped OS error (usually ENOENT or EACCES) includes the exact path that could not be opened.

Solutions

  1. Fix read permissions on the source tree (chmod -R u+r) or run packing as the file owner.
  2. Remove dangling symlinks / special files from the tree before packing.
  3. Delete tmpDir, re-extract the main JAR, and pack again to eliminate race conditions.
  4. Ensure no other process deletes files from the source directory while MakeJar runs.
Defensive patterns

Strategy: validation

Validate before calling

if fi.Mode()&0400 == 0 { return fmt.Errorf("unreadable file: %s", path) }
if fi.Mode()&os.ModeType != 0 && !fi.IsDir() { return fmt.Errorf("special file skipped: %s", path) }

Try / catch

f, err := os.Open(path)
if err != nil {
    var pe *fs.PathError
    if errors.As(err, &pe) && errors.Is(pe.Err, fs.ErrNotExist) {
        return nil // or log-and-skip policy for vanished files
    }
    return fmt.Errorf("error opening file %s: %w", path, err)
}

Prevention

When it happens

Trigger: Inside the walk callback, a non-directory entry cannot be opened: the file was deleted between Walk's stat and Open, its permissions deny read, it's a special/fifo file, or a symlink target is missing.

Common situations: Concurrent cleanup deleting files in tmpDir mid-pack; files extracted with mode 000 or owned by another user; dangling symlinks inside the extracted JAR tree; packing special device files.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/78dd930b8b91aaab. Report an issue: GitHub.

Appendix: source

Thrown at sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go:242

		}

		if fileInfo.IsDir() {
			fileHeader.Name += "/"
		} else {
			fileHeader.Method = zip.Deflate
		}

		writer, err := jarFile.CreateHeader(fileHeader)
		if err != nil {
			return fmt.Errorf("error creating jarFile header: %w", err)
		}
		if fileInfo.IsDir() {
			return nil
		}

		f, err := os.Open(path)
		if err != nil {
			return fmt.Errorf("error opening file %s: %w", path, err)
		}
		defer f.Close()

		if _, err = io.Copy(writer, f); err != nil {
			return fmt.Errorf("error copying file %s: %w", path, err)
		}
		return nil
	})
	return err
}

// MakeJar fetches additional classpath JARs and adds it to the classpath of
// main JAR file and compiles a fresh JAR.
func MakeJar(mainJar string, classpath string) (string, error) {
	usr, _ := user.Current()
	cacheDir := filepath.Join(usr.HomeDir, jarCache[2:])

	// fetch jars required in classpath

View on GitHub (pinned to 12126d8942)