apache/beam · error

error in creating jar

Error message

error in creating jar %s: %w

What it means

After a successful HTTP 200 response, getLocalJar creates the local destination file with os.Create(jarPath). This error wraps any failure of that file creation, meaning the jar could not be written at the computed jarPath. It always carries the underlying OS error (permission, nonexistent directory, disk full, etc.) via %w.

Solutions

  1. Create the parent directory of jarPath (mkdir -p) and ensure it is writable by the running user.
  2. Check disk space/quota with df on the target filesystem.
  3. Point the jar destination to a writable location (e.g. $TMPDIR or a mounted volume).
  4. Read the wrapped cause (%w) to identify the exact OS-level reason.

Example fix

// before
jarPath, err := expansionx.MakeJar(ctx, url, destDir) // destDir missing
// after
if err := os.MkdirAll(destDir, 0700); err != nil {
    return err
}
jarPath, err := expansionx.MakeJar(ctx, url, destDir)
Defensive patterns

Strategy: validation

Validate before calling

dir := filepath.Dir(jarPath)
if err := os.MkdirAll(dir, 0700); err != nil {
    return fmt.Errorf("cannot create jar dir %s: %w", dir, err)
}
if err := unix.Access(dir, unix.W_OK); err != nil {
    return fmt.Errorf("jar dir %s not writable: %v", dir, err)
}

Try / catch

jarPath, err := expansionx.MakeJar(ctx, url, dest)
if err != nil {
    var pe *fs.PathError
    if errors.As(errors.Unwrap(err), &pe) {
        log.Printf("jar write failed at %s: %v", pe.Path, pe.Err)
    }
    return err
}

Prevention

When it happens

Trigger: os.Create(jarPath) fails during getLocalJar: the cache directory does not exist, is read-only, or is owned by another user.

Common situations: Running in a container as non-root while the jar path points to a root-owned directory; HOME unset so the default cache path resolves badly; disk quota exceeded on CI runners.

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/b5c353bb266f5db4. Report an issue: GitHub.

Appendix: source

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

		strings.Contains(url, "maven.google.com") ||
		strings.Contains(url, "maven-central.storage-download.googleapis.com") {
		log.Printf("WARNING: Downloading JAR file from public repository: %s. "+
			"This may pose security risks or cause instability due to repository availability. Consider pre-staging dependencies or using private mirrors.", url)
	}

	resp, err := http.Get(string(url))
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()

	if resp.StatusCode != 200 {
		return "", fmt.Errorf("failed to connect to %v: received non 200 response code, got %v", url, resp.StatusCode)
	}

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

	_, err = io.Copy(file, resp.Body)
	if err != nil {
		return "", fmt.Errorf("error in coping file %s inside jar %s: %w", file.Name(), jarPath, err)
	}

	return jarPath, nil
}

func validatePath(dest, filename string) (string, error) {
	destPath := filepath.Join(dest, filename)
	cleanDest := filepath.Clean(dest)
	cleanPath := filepath.Clean(destPath)

	rel, err := filepath.Rel(cleanDest, cleanPath)
	if err != nil || strings.HasPrefix(rel, ".."+string(filepath.Separator)) || rel == ".." {
		return "", fmt.Errorf("file path %q is outside destination directory %q", filename, dest)

View on GitHub (pinned to 12126d8942)