-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix evaluateCause
loosing access to err
#109
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a unit test that exemplifies the issue.
|
||
return cause instanceof Error | ||
? cause | ||
: undefined | ||
} | ||
|
||
/** | ||
* @param {unknown|(()=>err)} cause | ||
* @param {Error|{ cause?: unknown|(()=>err)}} err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this change mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
evaluateCause
now takes the same argument as getErrorCause
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I completely missed we have that jsdoc. I don't think it is even valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't tell, haven't used JSDoc for a long time.
30d7481
to
08a0499
Compare
Agreed for the test, here it is. It fails before the fix. |
evaluateCause
loosing access to this
evaluateCause
loosing access to err
01cbb10
to
20c44ec
Compare
@voxpelli please take a look at this. |
20c44ec
to
3f81ce6
Compare
Instead rely on its content being appended to the message and the stack. This is an alternative fix to pinojs#94, replacing pinojs#105 and pinojs#108 + makes pinojs#109 not needed
I added an alternate solution to it, which removed the new competing serialization system and relies on the original summary system: #110 |
…ead (#110) * Revert "Nested VError causes (#108)" This reverts commit 5b88f7e. * Revert "Serialize errors with cause (#105)" This reverts commit ae83956. * Never serialize `.cause` when an `Error` Instead rely on its content being appended to the message and the stack. This is an alternative fix to #94, replacing #105 and #108 + makes #109 not needed * Add tests * Add explainer comment
This PR can be closed now that #110 has been merged |
Before this PR:
err
is not bound asthis
to thecause
method when callingevaluateCause
. The call tocause
executesError.prototype.cause
(or its overload), butthis
refers to the global object, whereas it should beerr
. This leads to errors as soon asthis
is used in thecause
method implementation.This PR fixes this behavior.