Skip to content

Commit b9dbfa7

Browse files
ursulabauerarr00
andauthored
Improve promise rejections handling in hardhat/async-test-sanity.js (#5429)
Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com>
1 parent 19c2f2f commit b9dbfa7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

hardhat/async-test-sanity.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
process.on('unhandledRejection', reason => {
2-
throw new Error(reason);
2+
// If the reason is already an Error object, throw it directly to preserve the stack trace.
3+
if (reason instanceof Error) {
4+
throw reason;
5+
} else {
6+
// If the reason is not an Error (e.g., a string, number, or other primitive),
7+
// create a new Error object with the reason as its message.
8+
throw new Error(`Unhandled rejection: ${reason}`);
9+
}
310
});

0 commit comments

Comments
 (0)