-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add error utils #146
Add error utils #146
Conversation
This commit satisfies a few needs that we have in various projects: - When catching a throwable from some kind of operation, we want to be able to test whether the throwable is an error. - Furthermore, since the Error interface in TypeScript is pretty simple, we want to be able to test for different properties on an error (`code`, `stack`, etc.). - We want to wrap an error produced by a lower level part of the system with a different message, but preserve the original error using the `cause` property (note: this property was added in Node 18, so for older Nodes, we use the `pony-cause` library to set this). - Finally, we want to be able to take a throwable and produce an error that has a stacktrace. This is particularly useful for working with the `fs.promises` module, which (as of Node 22) [does not produce proper stacktraces][1]. [1]: nodejs/node#30944
New dependencies detected. Learn more about Socket for GitHub ↗︎
|
I wrote some test cases for error objects with multiple properties: 41aba60. |
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.
A function to get an error message from an unknown
error would be nice too. We use this in various places in Snaps at least.
@Mrtenz I've added |
@MajorLift I added your tests. There were a couple of duplicate tests that I removed as we discussed. I also added a test for |
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.
Yes, the updates look good!
@MajorLift ^ I pushed one more change, sorry! |
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.
LGTM!
Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
This commit satisfies a few needs that we have in various projects:
code
,stack
, etc.).cause
property (note: this property was added in Node 18, so for older Nodes, we use thepony-cause
library to set this).fs.promises
module, which (as of Node 20) does not produce proper stacktraces.Places where we've used these kinds of utility functions:
Relates to MetaMask/module-lint#5.