Просмотр исходного кода

Improve promise rejections handling in hardhat/async-test-sanity.js (#5429)

Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com>
Ursula 8 месяцев назад
Родитель
Сommit
b9dbfa7ceb
1 измененных файлов с 8 добавлено и 1 удалено
  1. 8 1
      hardhat/async-test-sanity.js

+ 8 - 1
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}`);
+  }
 });