From b30341a3aa7e4e836589e91fb448e98ae4fdadb3 Mon Sep 17 00:00:00 2001 From: Nathan Walters Date: Fri, 27 Oct 2023 15:28:13 -0700 Subject: [PATCH 1/4] Ensure AggregateError is propagated without modification --- lib/asyncify.js | 2 +- test/asyncify.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/asyncify.js b/lib/asyncify.js index 21eebee1f..74ba75616 100644 --- a/lib/asyncify.js +++ b/lib/asyncify.js @@ -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 instanceof Error ? err : new Error(err)); }); } diff --git a/test/asyncify.js b/test/asyncify.js index f76c0a754..bbd3154e9 100644 --- a/test/asyncify.js +++ b/test/asyncify.js @@ -59,6 +59,19 @@ describe('asyncify', () => { } }); + it('propagates AggregateError', (done) => { + async.asyncify(async () => { + throw new AggregateError([new Error('foo'), new Error('bar')]); + })((err) => { + assert(err); + 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) => { From c448a86b753e89f8fdee569f87ff2b77ee92b43f Mon Sep 17 00:00:00 2001 From: Nathan Walters Date: Fri, 27 Oct 2023 15:34:46 -0700 Subject: [PATCH 2/4] Update test to not rely on AggregateError global --- test/asyncify.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/asyncify.js b/test/asyncify.js index bbd3154e9..3417b71d7 100644 --- a/test/asyncify.js +++ b/test/asyncify.js @@ -59,11 +59,14 @@ describe('asyncify', () => { } }); - it('propagates AggregateError', (done) => { + it('propagates error with empty message without modification', (done) => { + let originalErr; async.asyncify(async () => { - throw new AggregateError([new Error('foo'), new Error('bar')]); + 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'); From 9436c1c26557c0886eb46c1d61eb3990fce241b0 Mon Sep 17 00:00:00 2001 From: Nathan Sarang-Walters Date: Mon, 30 Oct 2023 13:54:42 -0700 Subject: [PATCH 3/4] Update lib/asyncify.js Co-authored-by: Alex Early --- lib/asyncify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/asyncify.js b/lib/asyncify.js index 74ba75616..13978b8d7 100644 --- a/lib/asyncify.js +++ b/lib/asyncify.js @@ -87,7 +87,7 @@ function handlePromise(promise, callback) { return promise.then(value => { invokeCallback(callback, null, value); }, err => { - invokeCallback(callback, err instanceof Error ? err : new Error(err)); + invokeCallback(callback, err && (err instanceof Error || err.message) ? err : new Error(err)); }); } From 8521e9d247860cb95fed2a90ea299ad8cc374b00 Mon Sep 17 00:00:00 2001 From: Nathan Walters Date: Fri, 3 Nov 2023 14:41:10 -0700 Subject: [PATCH 4/4] Update .eslintrc.json to use es2021 globals --- .eslintrc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index 17eca479a..e5e65bdc9 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,7 +2,7 @@ "env": { "browser": true, "node": true, - "es6": "es2021" + "es2021": true }, "parser": "@babel/eslint-parser", "parserOptions": {