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. |
Mrtenz
left a comment
There was a problem hiding this comment.
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 |
MajorLift
left a comment
There was a problem hiding this comment.
Yes, the updates look good!
|
@MajorLift ^ I pushed one more change, sorry! |
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.).causeproperty (note: this property was added in Node 18, so for older Nodes, we use thepony-causelibrary to set this).fs.promisesmodule, 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.