From e9e2d6cfa0638c4d2efac6b5c15aff270b85bcb4 Mon Sep 17 00:00:00 2001 From: Kai Ninomiya Date: Mon, 21 Apr 2025 13:56:00 -0700 Subject: [PATCH 1/2] Reland "Show error dialog on unhandled rejection and uncaught exception (#502)" (#509) Reland with fix. Reverted in #509. Original in #502. --- sample/util.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sample/util.ts b/sample/util.ts index b36fefb4..73ac0c21 100644 --- a/sample/util.ts +++ b/sample/util.ts @@ -1,3 +1,14 @@ +// Show an error dialog if there's any uncaught exception or promise rejection. +// This gets set up on all pages that include util.ts. +globalThis.addEventListener('unhandledrejection', (ev) => { + fail(`unhandled promise rejection, please report a bug! + https://github.com/webgpu/webgpu-samples/issues/new\n${ev.reason}`); +}); +globalThis.addEventListener('error', (ev) => { + fail(`uncaught exception, please report a bug! + https://github.com/webgpu/webgpu-samples/issues/new\n${ev.error}`); +}); + /** Shows an error dialog if getting an adapter wasn't successful. */ export function quitIfAdapterNotAvailable( adapter: GPUAdapter | null @@ -40,7 +51,6 @@ export function quitIfWebGPUNotAvailable( if (!device) { quitIfAdapterNotAvailable(adapter); fail('Unable to get a device for an unknown reason'); - return; } device.lost.then((reason) => { @@ -52,7 +62,7 @@ export function quitIfWebGPUNotAvailable( } /** Fail by showing a console error, and dialog box if possible. */ -const fail = (() => { +const fail: (message: string) => never = (() => { type ErrorOutput = { show(msg: string): void }; function createErrorOutput() { From cfbd50af8ee89d6322b30062cdcce68464feb55f Mon Sep 17 00:00:00 2001 From: Kai Ninomiya Date: Mon, 21 Apr 2025 16:23:02 -0700 Subject: [PATCH 2/2] undo unrelated nits --- sample/util.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sample/util.ts b/sample/util.ts index 73ac0c21..2628ba48 100644 --- a/sample/util.ts +++ b/sample/util.ts @@ -51,6 +51,7 @@ export function quitIfWebGPUNotAvailable( if (!device) { quitIfAdapterNotAvailable(adapter); fail('Unable to get a device for an unknown reason'); + return; } device.lost.then((reason) => { @@ -62,7 +63,7 @@ export function quitIfWebGPUNotAvailable( } /** Fail by showing a console error, and dialog box if possible. */ -const fail: (message: string) => never = (() => { +const fail = (() => { type ErrorOutput = { show(msg: string): void }; function createErrorOutput() {