Skip to content

Commit 0412f8d

Browse files
nwalters512aearly
andauthored
Ensure error objects are propagated without modification (#1920)
* 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]>
1 parent ab3c56a commit 0412f8d

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

.eslintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"env": {
33
"browser": true,
44
"node": true,
5-
"es6": "es2021"
5+
"es2021": true
66
},
77
"parser": "@babel/eslint-parser",
88
"parserOptions": {

lib/asyncify.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function handlePromise(promise, callback) {
8787
return promise.then(value => {
8888
invokeCallback(callback, null, value);
8989
}, err => {
90-
invokeCallback(callback, err && err.message ? err : new Error(err));
90+
invokeCallback(callback, err && (err instanceof Error || err.message) ? err : new Error(err));
9191
});
9292
}
9393

test/asyncify.js

+16
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ describe('asyncify', () => {
5959
}
6060
});
6161

62+
it('propagates error with empty message without modification', (done) => {
63+
let originalErr;
64+
async.asyncify(async () => {
65+
originalErr = new AggregateError([new Error('foo'), new Error('bar')]);
66+
throw originalErr;
67+
})((err) => {
68+
assert(err);
69+
assert.strictEqual(err, originalErr);
70+
expect(err.errors).to.be.an('array');
71+
expect(err.errors.length).to.equal(2);
72+
expect(err.errors[0].message).to.equal('foo');
73+
expect(err.errors[1].message).to.equal('bar');
74+
done();
75+
})
76+
})
77+
6278
describe('promisified', () => {
6379
function promisifiedTests(Promise) {
6480
it('resolve', (done) => {

0 commit comments

Comments
 (0)