From 979c98a3cb92c6e1901b2eefc3cd72fe2a3e56de Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sun, 28 Nov 2021 12:57:58 -0800 Subject: [PATCH] events: propagate abortsignal reason in new AbortError ctor in events Signed-off-by: James M Snell PR-URL: https://github.com/nodejs/node/pull/41008 Reviewed-By: Ruben Bridgewater Reviewed-By: Robert Nagy Reviewed-By: Benjamin Gruenbaum --- lib/events.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/events.js b/lib/events.js index b79c8a36cdc012..7abf18f42c0064 100644 --- a/lib/events.js +++ b/lib/events.js @@ -928,7 +928,7 @@ async function once(emitter, name, options = kEmptyObject) { const signal = options?.signal; validateAbortSignal(signal, 'options.signal'); if (signal?.aborted) - throw new AbortError(); + throw new AbortError(undefined, { cause: signal?.reason }); return new Promise((resolve, reject) => { const errorListener = (err) => { emitter.removeListener(name, resolver); @@ -955,7 +955,7 @@ async function once(emitter, name, options = kEmptyObject) { function abortListener() { eventTargetAgnosticRemoveListener(emitter, name, resolver); eventTargetAgnosticRemoveListener(emitter, 'error', errorListener); - reject(new AbortError()); + reject(new AbortError(undefined, { cause: signal?.reason })); } if (signal != null) { eventTargetAgnosticAddListener( @@ -1006,7 +1006,7 @@ function on(emitter, event, options) { const signal = options?.signal; validateAbortSignal(signal, 'options.signal'); if (signal?.aborted) - throw new AbortError(); + throw new AbortError(undefined, { cause: signal?.reason }); const unconsumedEvents = []; const unconsumedPromises = []; @@ -1094,7 +1094,7 @@ function on(emitter, event, options) { return iterator; function abortListener() { - errorHandler(new AbortError()); + errorHandler(new AbortError(undefined, { cause: signal?.reason })); } function eventHandler(...args) {