Skip to content

Commit

Permalink
Handle environments where Error.captureStackTrace is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
lostplan committed Jul 5, 2023
1 parent 76f1119 commit 2134a9f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/promise-pool-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export class PromisePoolError<T, E = any> 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)
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/validation-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/promise-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2134a9f

Please sign in to comment.