From 2134a9f7aa7f28339e38cb6fcd26d454c4574946 Mon Sep 17 00:00:00 2001 From: Sol Date: Wed, 5 Jul 2023 11:43:14 +0100 Subject: [PATCH] Handle environments where Error.captureStackTrace is not defined --- src/promise-pool-error.ts | 4 +++- src/validation-error.ts | 4 +++- test/promise-pool.js | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/promise-pool-error.ts b/src/promise-pool-error.ts index 137de32..69b7fbd 100644 --- a/src/promise-pool-error.ts +++ b/src/promise-pool-error.ts @@ -25,7 +25,9 @@ export class PromisePoolError extends Error { this.name = this.constructor.name this.message = this.messageFrom(error) - Error.captureStackTrace(this, this.constructor) + if (Error.captureStackTrace && typeof Error.captureStackTrace === 'function') { + Error.captureStackTrace(this, this.constructor) + } } /** diff --git a/src/validation-error.ts b/src/validation-error.ts index fff5010..c0c081d 100644 --- a/src/validation-error.ts +++ b/src/validation-error.ts @@ -9,7 +9,9 @@ export class ValidationError extends Error { constructor (message?: string) { super(message) - Error.captureStackTrace(this, this.constructor) + if (Error.captureStackTrace && typeof Error.captureStackTrace === 'function') { + Error.captureStackTrace(this, this.constructor) + } } /** diff --git a/test/promise-pool.js b/test/promise-pool.js index 2452074..12c067e 100644 --- a/test/promise-pool.js +++ b/test/promise-pool.js @@ -379,7 +379,7 @@ test('fails with string', async () => { ).toBe(true) }) -test('fails with Error and stacktrace', async () => { +test('fails with Error', async () => { const ids = [1, 2, 3] const { errors } = await PromisePool