fix(snackager): check HTTP status and handle stream errors when fetching tarballs#673
Open
fix(snackager): check HTTP status and handle stream errors when fetching tarballs#673
Conversation
…ing tarballs Why === `fetchAndExtract` pipes the fetch response body directly to a file without checking `response.ok`. If the npm registry returns a 404 or 500, the error response body gets written to `package.tgz`, and then `targz.decompress` fails with an opaque decompression error instead of a clear "tarball fetch failed with status 404" message. Additionally, the `response.body` stream's `error` event isn't handled, so a mid-download network failure (connection reset, timeout) leaves the promise unresolved with a partial `.tgz` file. How === Check `response.ok` before piping and throw with the HTTP status if the request failed. Listen for the `error` event on `response.body` to catch mid-download failures and reject the promise. No cleanup of partial `.tgz` files is needed since the caller's `finally` block in `fetchBundle.ts` already `rimraf`s the parent directory. Test Plan === `yarn build` and `yarn test` pass.
ide
commented
Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
fetchAndExtractpipes the fetch response body directly to a file without checkingresponse.ok. If the npm registry returns a 404 or 500, the error response body gets written topackage.tgz, and thentargz.decompressfails with an opaque decompression error instead of a clear "tarball fetch failed with status 404" message. Additionally, theresponse.bodystream'serrorevent isn't handled, so a mid-download network failure (connection reset, timeout) leaves the promise unresolved with a partial.tgzfile.How
Check
response.okbefore piping and throw with the HTTP status if the request failed. Listen for theerrorevent onresponse.bodyto catch mid-download failures and reject the promise. No cleanup of partial.tgzfiles is needed since the caller'sfinallyblock infetchBundle.tsalreadyrimrafs the parent directory.Test Plan
yarn buildandyarn testpass.