Skip to content

Commit 01082a4

Browse files
piehisaacs
authored andcommitted
fix: reject top promise on floating addFilesAsync rejections
PR-URL: #455 Credit: @pieh Close: #455 Reviewed-by: @isaacs
1 parent dd1c36a commit 01082a4

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/create.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const createFile = (opt: TarOptionsFile, files: string[]) => {
3333
p.on('error', rej)
3434
})
3535

36-
addFilesAsync(p, files)
36+
addFilesAsync(p, files).catch(er => p.emit('error', er))
3737

3838
return promise
3939
}
@@ -79,7 +79,7 @@ const createSync = (opt: TarOptionsSync, files: string[]) => {
7979

8080
const createAsync = (opt: TarOptions, files: string[]) => {
8181
const p = new Pack(opt)
82-
addFilesAsync(p, files)
82+
addFilesAsync(p, files).catch(er => p.emit('error', er))
8383
return p
8484
}
8585

test/create.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,37 @@ t.test('must specify some files', t => {
289289
t.end()
290290
})
291291

292+
t.test('error from @ file entry should be catchable', t => {
293+
t.test('async with file option', t => {
294+
const file = path.resolve(dir, 'at-error-file.tar')
295+
t.rejects(
296+
c(
297+
{
298+
file: file,
299+
cwd: __dirname,
300+
},
301+
['@nonexistent.tar'],
302+
),
303+
).then(() => t.end())
304+
})
305+
306+
t.test('async without file option', t => {
307+
const stream = c(
308+
{
309+
cwd: __dirname,
310+
},
311+
['@nonexistent.tar'],
312+
)
313+
stream.on('error', er => {
314+
t.match(er, { code: 'ENOENT' })
315+
t.end()
316+
})
317+
stream.resume()
318+
})
319+
320+
t.end()
321+
})
322+
292323
t.test('transform a filename', async t => {
293324
const cwd = t.testdir({
294325
'README.md': 'hello, world',

0 commit comments

Comments
 (0)