Skip to content

Commit

Permalink
Fix evaluateCause loosing access to this
Browse files Browse the repository at this point in the history
  • Loading branch information
KoltesDigital committed Jun 13, 2022
1 parent d8ce240 commit 30d7481
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions lib/err-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
const getErrorCause = (err) => {
if (!err) return

const cause = evaluateCause(err.cause)
const cause = evaluateCause(err)

return cause instanceof Error
? cause
: undefined
}

/**
* @param {unknown|(()=>err)} cause
* @param {Error|{ cause?: unknown|(()=>err)}} err
* @returns {Error|undefined}
*/
const evaluateCause = (cause) => {
const evaluateCause = (err) => {
// VError / NError style causes are functions
return typeof cause === 'function'
? cause()
: cause
return typeof err.cause === 'function'
? err.cause()
: err.cause
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/err.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function errSerializer (err) {
}

if (err.cause) {
const cause = evaluateCause(err.cause)
const cause = evaluateCause(err)
_err.cause = errSerializer(cause)
}

Expand Down

0 comments on commit 30d7481

Please sign in to comment.