Skip to content

Commit a1bafc9

Browse files
authored
Show error dialog on unhandled rejection and uncaught exception (#502)
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.: #501 (comment)
1 parent 85e141c commit a1bafc9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

sample/util.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
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, please report a bug!
5+
https://github.com/webgpu/webgpu-samples/issues/new\n${ev.reason}`);
6+
});
7+
window.addEventListener('error', (ev) => {
8+
fail(`uncaught exception, please report a bug!
9+
https://github.com/webgpu/webgpu-samples/issues/new\n${ev.error}`);
10+
});
11+
112
/** Shows an error dialog if getting an adapter wasn't successful. */
213
export function quitIfAdapterNotAvailable(
314
adapter: GPUAdapter | null

0 commit comments

Comments
 (0)