From 366bac2c4f369fe683cf5682f08f87e05f31c0fc Mon Sep 17 00:00:00 2001 From: Warren James Date: Tue, 23 Apr 2024 15:24:44 -0400 Subject: [PATCH] move error construction out of Timeout constructor --- src/timeout.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/timeout.ts b/src/timeout.ts index 7191f981de4..fadf9727a63 100644 --- a/src/timeout.ts +++ b/src/timeout.ts @@ -33,7 +33,6 @@ export class Timeout extends Promise { return 'MongoDBTimeout'; } - private timeoutError: TimeoutError; private id?: NodeJS.Timeout; public readonly start: number; @@ -55,9 +54,6 @@ export class Timeout extends Promise { executor(noop, promiseReject); }); - // NOTE: Construct timeout error at point of Timeout instantiation to preserve stack traces - this.timeoutError = new TimeoutError(`Expired after ${duration}ms`); - this.duration = duration; this.start = Math.trunc(performance.now()); @@ -65,7 +61,7 @@ export class Timeout extends Promise { this.id = setTimeout(() => { this.ended = Math.trunc(performance.now()); this.timedOut = true; - reject(this.timeoutError); + reject(new TimeoutError(`Expired after ${duration}ms`)); }, this.duration); // Ensure we do not keep the Node.js event loop running if (typeof this.id.unref === 'function') {