apache/beam · error
error opening source file
Error message
error opening source file %s: %w
What it means
For each non-directory zip entry, extractJar opens the embedded file with file.Open(); this error wraps that failure along with the entry name. It means the archive entry itself could not be read — usually a corrupt or truncated zip central/local header rather than a filesystem problem, since the entry lives inside the already-opened archive.
Solutions
- Re-download the jar and retry extraction.
- Test the archive with `unzip -t` to confirm corruption.
- Verify the download completed (HTTP 200 and full io.Copy) before extracting.
- If unsupported compression, re-zip the contents with standard DEFLATE.
Example fix
// before
jarPath, err := expansionx.MakeJar(ctx, url, dest) // extract fails on truncated jar
// after
if fi, statErr := os.Stat(jarPath); statErr != nil || fi.Size() != expectedSize {
os.Remove(jarPath)
jarPath, err = expansionx.MakeJar(ctx, url, dest)
} Defensive patterns
Strategy: validation
Validate before calling
// Verify archive integrity before extraction
r, err := zip.OpenReader(jarPath)
if err != nil { return err }
for _, f := range r.File {
rc, err := f.Open()
if err != nil { return fmt.Errorf("entry %q unreadable; jar corrupt", f.Name) }
rc.Close()
} Try / catch
err := expansionx.MakeJar(ctx, url, dest)
if err != nil && strings.Contains(err.Error(), "error opening source file") {
os.Remove(jarPath)
return fmt.Errorf("corrupt jar; re-download from %s", url)
} Prevention
- Confirm downloads complete (status 200, expected byte count) before caching.
- Test archives with `unzip -t` in setup/CI scripts.
- Avoid proxies that mangle binary payloads (enable binary passthrough).
- Delete and re-download jars on any extraction failure instead of reusing them.
When it happens
Trigger: file.Open() (zip.File.Open) fails during extractJar: corrupt entry metadata, unsupported compression method, or truncated archive bytes.
Common situations: Partially downloaded jar (connection cut mid-copy); jar damaged in transit through a mangling proxy; archive using a compression method Go's archive/zip doesn't support.
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
- error copying file
- error creating jarFile header
- error opening jar for extractJar
- bucket must not be empty
- chunk write failed
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/1ab8556806e4ca91.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go:176
}
if err := os.MkdirAll(dest, 0700); err != nil {
return fmt.Errorf("error creating directory %s in extractJar(%s,%s): %w", dest, source, dest, err)
}
for _, file := range reader.File {
fileName, err := validatePath(dest, file.Name)
if err != nil {
return fmt.Errorf("error validating file path (%s, %s): %w", dest, file.Name, err)
}
if file.FileInfo().IsDir() {
os.MkdirAll(fileName, 0700)
continue
}
sf, err := file.Open()
if err != nil {
return fmt.Errorf("error opening source file %s: %w", file.Name, err)
}
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)View on GitHub (pinned to 12126d8942)