Skip to content

Commit fc94a16

Browse files
stharcanis
authored andcommitted
Make sure TarballFetcher error messages contain names of problematic files (#5964)
* Make sure name of broken file is mentioned in error message * Pass when creating stream This isn't required to open the file (`fd` is used), but it allows the stream to have a useful `path` attribute.
1 parent bdf4acc commit fc94a16

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

__tests__/fetchers.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,10 @@ test('TarballFetcher.fetch throws on truncated tar data', async () => {
313313
},
314314
await Config.create({}, reporter),
315315
);
316-
await expect(fetcher.fetch()).rejects.toThrow(new RegExp(reporter.lang('errorExtractingTarball', '.*', '.*')));
316+
await expect(fetcher.fetch()).rejects.toThrow(
317+
// The "." in ".tgz" should be escaped, but that doesn't work with reporter.lang
318+
new RegExp(reporter.lang('errorExtractingTarball', '.*', '.*broken-tar-data.tgz')),
319+
);
317320
});
318321

319322
test('TarballFetcher.fetch throws on truncated tar header', async () => {
@@ -329,5 +332,8 @@ test('TarballFetcher.fetch throws on truncated tar header', async () => {
329332
},
330333
await Config.create({}, reporter),
331334
);
332-
await expect(fetcher.fetch()).rejects.toThrow(new RegExp(reporter.lang('errorExtractingTarball', '.*', '.*')));
335+
await expect(fetcher.fetch()).rejects.toThrow(
336+
// The "." in ".tgz" should be escaped, but that doesn't work with reporter.lang
337+
new RegExp(reporter.lang('errorExtractingTarball', '.*', '.*broken-tar-header.tgz')),
338+
);
333339
});

src/util/fs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ export async function readFirstAvailableStream(
823823
if (tarballPath) {
824824
try {
825825
const fd = await open(tarballPath, 'r');
826-
stream = fs.createReadStream('', {fd});
826+
stream = fs.createReadStream(tarballPath, {fd});
827827
break;
828828
} catch (err) {
829829
// Try the next one

0 commit comments

Comments
 (0)