-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: simplify isNodeExceptionLike check
in some environments, particularly jsdom with jest, Error objects may not be `instanceof Error` despite being similar and used in the same way. To avoid these issues we only need to validate the shape and properties that might be thrown. In some cases these could false positive, however it's less likely that they'll false positive, than it is that jest/jsdom will throw these objects _like_ the errors they represent (guaranteed)
- Loading branch information
1 parent
1589e83
commit 83347ff
Showing
3 changed files
with
19 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Determines if the given value is shaped like a Node.js exception. | ||
* Node.js exceptions have additional information, like | ||
* the `code` and `errno` properties. | ||
* | ||
* In some environments, particularly jsdom/jest these may not | ||
* instances of `Error` or its subclasses, despite being similar | ||
* to them. | ||
*/ | ||
export function isNodeExceptionLike( | ||
error: unknown, | ||
): error is NodeJS.ErrnoException { | ||
return !!error && typeof error === 'object' && 'code' in error | ||
} |