Skip to content

Commit

Permalink
fix: print a better error message on broken tarballs (#5746)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed Dec 4, 2022
1 parent 88600fb commit bcf2d54
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions fetching/tarball-fetcher/src/remoteTarballFetcher.ts
Expand Up @@ -173,6 +173,15 @@ export function createDownloader (

resolve({ filesIndex })
} catch (err: any) { // eslint-disable-line
// If the error is not an integrity check error, then it happened during extracting the tarball
if (
err['code'] !== 'ERR_PNPM_TARBALL_INTEGRITY' &&
err['code'] !== 'ERR_PNPM_BAD_TARBALL_SIZE'
) {
const extractError = new PnpmError('TARBALL_EXTRACT', `Failed to unpack the tarball from "${url}": ${err.message as string}`)
reject(extractError)
return
}
reject(err)
}
})
Expand Down
21 changes: 21 additions & 0 deletions fetching/tarball-fetcher/test/fetch.ts
Expand Up @@ -359,3 +359,24 @@ test('fetch a big repository', async () => {

expect(result.filesIndex).toBeTruthy()
})

test('fail when extracting a broken tarball', async () => {
const scope = nock(registry)
.get('/foo.tgz')
.times(2)
.reply(200, 'this is not a valid tarball')

process.chdir(tempy.directory())

const resolution = {
tarball: `${registry}foo.tgz`,
}

await expect(
fetch.remoteTarball(cafs, resolution, {
lockfileDir: process.cwd(),
})
).rejects.toThrow(`Failed to unpack the tarball from "${registry}foo.tgz": Unexpected end of data`
)
expect(scope.isDone()).toBeTruthy()
})

0 comments on commit bcf2d54

Please sign in to comment.