From 4f890832829aaa03ffa6b5675debcd8453ea8542 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sat, 24 Jul 2021 02:39:10 +0200 Subject: [PATCH] Fix bug that interrupts error handling early --- index.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 4361d5b..569b4d6 100644 --- a/index.js +++ b/index.js @@ -66,20 +66,22 @@ module.exports = function simpleSinkStream(_options) { return attemptRead(); }).catch(isEndOfStream, (error) => { /* Don't attempt to do another read, we're done. */ - if (!onEndCalled && onEnd != null) { - onEndCalled = true; - - return Promise.try(() => { - return onEnd(); - }).then((result) => { - if (result !== undefined) { - resultBuffer.push(result); - } + return Promise.try(() => { + if (!onEndCalled && onEnd != null) { + onEndCalled = true; + + return Promise.try(() => { + return onEnd(); + }).then((result) => { + if (result !== undefined) { + resultBuffer.push(result); + } + }); + } + }).then(() => { + return resultBuffer.maybeRead(() => { + throw error; }); - } - - return resultBuffer.maybeRead(() => { - throw error; }); }).catch((error) => !isAborted(error), (error) => { return Promise.try(() => {