-
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
Make use of err.cause
when available
#76
Comments
What are we looking to accomplish? Also, I'd rather just support standard |
If the change to this module is minimal, +1 in doing it without deps I think this is likely. Otherwise add the dependency. |
I added a quick PR using my module: #78 I can of course look into making it a self-hosted solution instead if preferable. |
What
As the Error Cause tc39 proposal has reached stage 4 and is accepted + part of Node.js since version
16.9.0
I think it would be great if these serializers started to use them.Historical context
Also: For a long while before this proposal there was Joyent's
VError
module, which eg. was recommended in this Joyent article from +7 years ago and which was adopted by eg. Netflix who forked it as NError.VError
also uses.cause
but in their case it points to a method that returns the cause rather than the cause itself.Related approaches
I myself created a module,
pony-cause
, which apart from providing a polyfill for Error Causes (ErrorWithCause
) also provides a couple of helpers which supports official Error Causes as well as VError/NError causes, two which would be helpful here:messageWithCauses
– resolves the messages from all causes into a single message, using the style ofVError
which is: To join them together using the equivalent of.join(': ')
stackWithCauses
– provides causes for the full chain, also similar to howVError
does:This approach follows the prior art of
VError
/NError
and extends it to support the new Error Causes, making it a neat approach.This also aligns with the support for
VError
style errors whichbunyan
has, but with the addition of supporting that format for new Error Causes as well.Suggested approach
Either implement the functionality of my
pony-cause
module directly in this module or pull in mypony-cause
module to:messageWithCauses
to set themessage
property.stackWithCauses
to set thecause
property.Related discussions
Will/can I submit a PR?
Yes 👍
The text was updated successfully, but these errors were encountered: