From 504d2936ecf1a5520ca20f83792a94b219e84f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 23 Jul 2022 00:40:42 +0200 Subject: fix: unhandledrejection handling for sync throw in top level (#15279) Fixes an edge in "unhandledrejection" event that prevent synchronous errors being surfaced when throw from a top-level scope. --- cli/tests/testdata/unhandled_rejection_sync_error.ts | 6 ++++++ cli/tests/testdata/unhandled_rejection_sync_error.ts.out | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 cli/tests/testdata/unhandled_rejection_sync_error.ts create mode 100644 cli/tests/testdata/unhandled_rejection_sync_error.ts.out (limited to 'cli/tests/testdata') diff --git a/cli/tests/testdata/unhandled_rejection_sync_error.ts b/cli/tests/testdata/unhandled_rejection_sync_error.ts new file mode 100644 index 000000000..0dabb1cb7 --- /dev/null +++ b/cli/tests/testdata/unhandled_rejection_sync_error.ts @@ -0,0 +1,6 @@ +globalThis.addEventListener("unhandledrejection", (e) => { + console.log("unhandled rejection at:", e.promise, "reason:", e.reason); + e.preventDefault(); +}); + +throw new Error("boom!"); diff --git a/cli/tests/testdata/unhandled_rejection_sync_error.ts.out b/cli/tests/testdata/unhandled_rejection_sync_error.ts.out new file mode 100644 index 000000000..270319824 --- /dev/null +++ b/cli/tests/testdata/unhandled_rejection_sync_error.ts.out @@ -0,0 +1,6 @@ +[WILDCARD] +unhandled rejection at: Promise { + Error: boom! + at file:///[WILDCARD]testdata/unhandled_rejection_sync_error.ts:6:7 +} reason: Error: boom! + at file:///[WILDCARD]testdata/unhandled_rejection_sync_error.ts:6:7 -- cgit v1.2.3