From 6827b27e509f1daea55ab12a199a340ca5432405 Mon Sep 17 00:00:00 2001 From: Nadeem Jamali <53427821+candeemis@users.noreply.github.com> Date: Thu, 17 Dec 2020 05:35:23 +0100 Subject: [PATCH] Finalize should always return a promise (#480) In case of error, the promise should be rejected rather than returning the 'this' object. The problem is discussed in detail here :point_right https://github.com/archiverjs/node-archiver/issues/344. --- lib/core.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/core.js b/lib/core.js index fe49dd4a..09cd8ed7 100644 --- a/lib/core.js +++ b/lib/core.js @@ -769,13 +769,15 @@ Archiver.prototype.glob = function(pattern, options, data) { */ Archiver.prototype.finalize = function() { if (this._state.aborted) { - this.emit('error', new ArchiverError('ABORTED')); - return this; + var abortedError = new ArchiverError('ABORTED'); + this.emit('error', abortedError); + return Promise.reject(abortedError); } if (this._state.finalize) { - this.emit('error', new ArchiverError('FINALIZING')); - return this; + var finalizingError = new ArchiverError('FINALIZING'); + this.emit('error', finalizingError); + return Promise.reject(finalizingError); } this._state.finalize = true;