From b9dbfa7cebc2e867dd9e376e4806095f1b31ff43 Mon Sep 17 00:00:00 2001 From: Ursula Date: Tue, 4 Feb 2025 11:55:06 +0200 Subject: [PATCH] Improve promise rejections handling in hardhat/async-test-sanity.js (#5429) Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com> --- hardhat/async-test-sanity.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hardhat/async-test-sanity.js b/hardhat/async-test-sanity.js index c05e5bd48..8e60f70d5 100644 --- a/hardhat/async-test-sanity.js +++ b/hardhat/async-test-sanity.js @@ -1,3 +1,10 @@ process.on('unhandledRejection', reason => { - throw new Error(reason); + // If the reason is already an Error object, throw it directly to preserve the stack trace. + if (reason instanceof Error) { + throw reason; + } else { + // If the reason is not an Error (e.g., a string, number, or other primitive), + // create a new Error object with the reason as its message. + throw new Error(`Unhandled rejection: ${reason}`); + } });