Skip to content

Commit

Permalink
Ensure error objects are propagated without modification (#1920)
Browse files Browse the repository at this point in the history
* Ensure AggregateError is propagated without modification

* Update test to not rely on AggregateError global

* Update lib/asyncify.js

Co-authored-by: Alex Early <[email protected]>

* Update .eslintrc.json to use es2021 globals

---------

Co-authored-by: Alex Early <[email protected]>
  • Loading branch information
nwalters512 and aearly authored Nov 3, 2023
1 parent ab3c56a commit 0412f8d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"env": {
"browser": true,
"node": true,
"es6": "es2021"
"es2021": true
},
"parser": "@babel/eslint-parser",
"parserOptions": {
Expand Down
2 changes: 1 addition & 1 deletion lib/asyncify.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function handlePromise(promise, callback) {
return promise.then(value => {
invokeCallback(callback, null, value);
}, err => {
invokeCallback(callback, err && err.message ? err : new Error(err));
invokeCallback(callback, err && (err instanceof Error || err.message) ? err : new Error(err));
});
}

Expand Down
16 changes: 16 additions & 0 deletions test/asyncify.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ describe('asyncify', () => {
}
});

it('propagates error with empty message without modification', (done) => {
let originalErr;
async.asyncify(async () => {
originalErr = new AggregateError([new Error('foo'), new Error('bar')]);
throw originalErr;
})((err) => {
assert(err);
assert.strictEqual(err, originalErr);
expect(err.errors).to.be.an('array');
expect(err.errors.length).to.equal(2);
expect(err.errors[0].message).to.equal('foo');
expect(err.errors[1].message).to.equal('bar');
done();
})
})

describe('promisified', () => {
function promisifiedTests(Promise) {
it('resolve', (done) => {
Expand Down

0 comments on commit 0412f8d

Please sign in to comment.