Skip to content

Commit

Permalink
Finalize should always return a promise (#480)
Browse files Browse the repository at this point in the history
In case of error, the promise should be rejected rather than returning the 'this' object. The problem is discussed in detail here :point_right #344.
  • Loading branch information
candeemis authored Dec 17, 2020
1 parent 2e0edfa commit 6827b27
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6827b27

Please sign in to comment.