{"record":{"id":"1ab8556806e4ca91","repo":"apache/beam","slug":"error-opening-source-file-s-w","errorCode":null,"errorMessage":"error opening source file %s: %w","messagePattern":"error opening source file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go","lineNumber":176,"sourceCode":"\t}\n\n\tif err := os.MkdirAll(dest, 0700); err != nil {\n\t\treturn fmt.Errorf(\"error creating directory %s in extractJar(%s,%s): %w\", dest, source, dest, err)\n\t}\n\n\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)","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go#L158-L194","documentation":"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.","triggerScenarios":"file.Open() (zip.File.Open) fails during extractJar: corrupt entry metadata, unsupported compression method, or truncated archive bytes.","commonSituations":"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.","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."],"exampleFix":"// before\njarPath, err := expansionx.MakeJar(ctx, url, dest) // extract fails on truncated jar\n// after\nif fi, statErr := os.Stat(jarPath); statErr != nil || fi.Size() != expectedSize {\n    os.Remove(jarPath)\n    jarPath, err = expansionx.MakeJar(ctx, url, dest)\n}","handlingStrategy":"validation","validationCode":"// Verify archive integrity before extraction\nr, err := zip.OpenReader(jarPath)\nif err != nil { return err }\nfor _, f := range r.File {\n    rc, err := f.Open()\n    if err != nil { return fmt.Errorf(\"entry %q unreadable; jar corrupt\", f.Name) }\n    rc.Close()\n}","typeGuard":null,"tryCatchPattern":"err := expansionx.MakeJar(ctx, url, dest)\nif err != nil && strings.Contains(err.Error(), \"error opening source file\") {\n    os.Remove(jarPath)\n    return fmt.Errorf(\"corrupt jar; re-download from %s\", url)\n}","preventionTips":["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."],"tags":["go","zip","io","corrupt-file"],"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"}