{"record":{"id":"1ef7b2b45389233b","repo":"anomalyco/sst","slug":"failed-to-open-archive-w","errorCode":null,"errorMessage":"failed to open archive: %w","messagePattern":"failed to open archive: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/runtime/python/build.go","lineNumber":401,"sourceCode":"\t\t\treturn err\n\t\t}\n\n\t\tif _, err := io.Copy(out, rc); err != nil {\n\t\t\tout.Close()\n\t\t\trc.Close()\n\t\t\treturn err\n\t\t}\n\t\tout.Close()\n\t\trc.Close()\n\t}\n\treturn nil\n}\n\n// extractTarGz extracts a .tar.gz archive to the destination directory.\nfunc extractTarGz(archiveFile, destDir string) error {\n\tf, err := os.Open(archiveFile)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open archive: %w\", err)\n\t}\n\tdefer f.Close()\n\n\tgz, err := gzip.NewReader(f)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create gzip reader: %w\", err)\n\t}\n\tdefer gz.Close()\n\n\ttr := tar.NewReader(gz)\n\tfor {\n\t\thdr, err := tr.Next()\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to read tar entry: %w\", err)\n\t\t}","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/pkg/runtime/python/build.go#L383-L419","documentation":"extractTarGz wraps any failure from os.Open(archiveFile) with the message \"failed to open archive\". It fires when the downloaded/located .tar.gz package file cannot be opened for reading — the file is missing, the path is wrong, or the process lacks read permission. The original OS error is preserved via %w so callers can inspect it with errors.Is/As.","triggerScenarios":"processPackageArchive calls extractTarGz with an archiveFile path that does not exist, was deleted between download and extraction, or cannot be opened due to permissions (os.Open returns an error such as ENOENT, EACCES, or EISDIR).","commonSituations":"A pip-download step failed silently leaving no wheel/sdist on disk; the archive path was built with a wrong hash or version directory; a temp directory was cleaned up prematurely; a Docker/CI cache references a file that no longer exists; the file is read-only for the build user.","solutions":["Verify the archive file exists at the expected path (ls/stat the path from the error context) before re-running the build","Re-run the package download step (pip download / uv pip) so the .tar.gz is recreated","Check file permissions and that the build process user can read the archive","Clear stale build caches and rebuild so the archive is re-fetched","Check disk space and mount health if the file lives on a volume"],"exampleFix":"// before: extracting a possibly-missing archive\nextractTarGz(archiveFile, destDir)\n\n// after: check existence first\nif _, err := os.Stat(archiveFile); err != nil {\n    return fmt.Errorf(\"archive missing, re-download package: %w\", err)\n}\nif err := extractTarGz(archiveFile, destDir); err != nil {\n    return err\n}","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(archiveFile); err != nil {\n    return fmt.Errorf(\"archive %s not available: %w\", archiveFile, err)\n}\nif info, _ := os.Stat(archiveFile); info.Size() == 0 {\n    return fmt.Errorf(\"archive %s is empty\", archiveFile)\n}","typeGuard":null,"tryCatchPattern":"if err := extractTarGz(archiveFile, destDir); err != nil {\n    var pathErr *os.PathError\n    if errors.As(err, &pathErr) && errors.Is(pathErr.Err, os.ErrNotExist) {\n        // re-download the archive and retry\n    }\n    return err\n}","preventionTips":["Stat the archive before extraction","Re-download on every build when integrity is in doubt instead of trusting caches","Run builds as a user with read access to the cache directory","Fail fast after download by checking file size > 0"],"tags":["filesystem","io","python","packaging"],"backgroundTag":"file-not-found","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}