From 46167ce2ca8a5ecde4bf252477f882e96e4cb6db Mon Sep 17 00:00:00 2001 From: Louis-Dominique Dubeau Date: Tue, 2 Jul 2019 16:09:36 -0400 Subject: [PATCH] fix(git): ensure stream failures are reported up the promise chain Prior to the change, race conditions could cause errors on the stream to be lost. The symptom for npm users would be the infamous "cb() never called" error. --- extract.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/extract.js b/extract.js index d2ab47de..f49a5442 100644 --- a/extract.js +++ b/extract.js @@ -50,21 +50,22 @@ function extract (spec, dest, opts) { function tryExtract (spec, tarStream, dest, opts) { return new BB((resolve, reject) => { tarStream.on('error', reject) - setImmediate(resolve) + + rimraf(dest) + .then(() => mkdirp(dest)) + .then(() => { + const xtractor = extractStream(spec, dest, opts) + xtractor.on('error', reject) + xtractor.on('close', resolve) + tarStream.pipe(xtractor) + }) + .catch(reject) }) - .then(() => rimraf(dest)) - .then(() => mkdirp(dest)) - .then(() => new BB((resolve, reject) => { - const xtractor = extractStream(spec, dest, opts) - tarStream.on('error', reject) - xtractor.on('error', reject) - xtractor.on('close', resolve) - tarStream.pipe(xtractor) - })) .catch(err => { if (err.code === 'EINTEGRITY') { err.message = `Verification failed while extracting ${spec}:\n${err.message}` } + throw err }) }