Skip to content

Commit 1d738dc

Browse files
committed
Show error dialog on unhandled rejection and uncaught exception
These errors aren't supposed to happen in the samples, but if they do, we want them to be visible. Otherwise they can only be seen in the dev tools console, and sometimes you can't tell that the sample is misbehaving, e.g.: webgpu#501 (comment)
1 parent 85e141c commit 1d738dc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

sample/util.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
// Show an error dialog if there's any uncaught exception or promise rejection.
2+
// This gets set up on all pages that include util.ts.
3+
window.addEventListener('unhandledrejection', ev => {
4+
fail(`unhandled promise rejection:\n${ev.reason}`);
5+
});
6+
window.addEventListener('error', ev => {
7+
fail(`uncaught exception:\n${ev.error}`);
8+
});
9+
110
/** Shows an error dialog if getting an adapter wasn't successful. */
211
export function quitIfAdapterNotAvailable(
312
adapter: GPUAdapter | null

0 commit comments

Comments
 (0)