apache/beam · error

error creating jar packJar

Error message

error creating jar packJar(%s,%s)=%w

What it means

packJar could not create the destination JAR file itself via os.Create(dest). This is the first step of repackaging the extracted JAR plus new classpath entries, so any failure here aborts MakeJar before any content is written. The wrapped OS error names both the source tree and the target path.

Solutions

  1. Ensure the destination directory for the output jar exists and is writable (create/chmod/chown it).
  2. Check the dest path does not resolve to an existing directory; remove or rename it.
  3. Free disk space if df shows a full volume.
  4. Verify the process user can write to $HOME where the Beam jar cache lives.

Example fix

// before: read-only HOME in container
ENV HOME=/nonexistent
// after: provide a writable home for the jar cache
ENV HOME=/home/beam
RUN mkdir -p /home/beam && chown beam:beam /home/beam
Defensive patterns

Strategy: validation

Validate before calling

destDir := filepath.Dir(dest)
if info, err := os.Stat(destDir); err != nil || !info.IsDir() {
    os.MkdirAll(destDir, 0700)
}
if fi, err := os.Stat(dest); err == nil && fi.IsDir() {
    return fmt.Errorf("dest %s is a directory", dest)
}
probe, err := os.CreateTemp(destDir, ".writecheck")
if err != nil { return err }
probe.Close(); os.Remove(probe.Name())

Try / catch

jar, err := os.Create(dest)
if err != nil {
    return fmt.Errorf("error creating jar packJar(%s,%s)=%w", source, dest, err)
}

Prevention

When it happens

Trigger: os.Create(dest) fails because the destination directory does not exist or is unwritable, the path points to a directory, or disk/permission limits (EACCES, ENOENT, EISDIR, ENOSPC) apply.

Common situations: $HOME/.beam661bea09-... cache dir deleted or mounted read-only between extract and pack steps; a directory named like the output jar already exists; container running with read-only filesystem or as wrong user.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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

Appendix: source

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

		defer sf.Close()

		df, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0777)
		if err != nil {
			return fmt.Errorf("error opening destination file %s: %w", fileName, err)
		}
		defer df.Close()

		if _, err := io.Copy(df, sf); err != nil {
			return err
		}
	}
	return nil
}

func packJar(source, dest string) error {
	jar, err := os.Create(dest)
	if err != nil {
		return fmt.Errorf("error creating jar packJar(%s,%s)=%w", source, dest, err)
	}
	defer jar.Close()

	jarFile := zip.NewWriter(jar)
	defer jarFile.Close()

	fileInfo, err := os.Stat(source)
	if err != nil {
		return fmt.Errorf("source path %s doesn't exist: %w", source, err)
	}

	var sourceDir string
	if fileInfo.IsDir() {
		sourceDir = filepath.Base(source)
	}

	err = filepath.Walk(source, func(path string, fileInfo os.FileInfo, err error) error {
		if err != nil {

View on GitHub (pinned to 12126d8942)