|
| 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 | +globalThis.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 | +globalThis.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 | + |
1 | 12 | /** Shows an error dialog if getting an adapter wasn't successful. */ |
2 | 13 | export function quitIfAdapterNotAvailable( |
3 | 14 | adapter: GPUAdapter | null |
@@ -40,19 +51,18 @@ export function quitIfWebGPUNotAvailable( |
40 | 51 | if (!device) { |
41 | 52 | quitIfAdapterNotAvailable(adapter); |
42 | 53 | fail('Unable to get a device for an unknown reason'); |
43 | | - return; |
44 | 54 | } |
45 | 55 |
|
46 | 56 | device.lost.then((reason) => { |
47 | 57 | fail(`Device lost ("${reason.reason}"):\n${reason.message}`); |
48 | 58 | }); |
49 | | - device.addEventListener('uncapturederror', (ev) => { |
| 59 | + device.addEventListener('uncapturederror', (ev: GPUUncapturedErrorEvent) => { |
50 | 60 | fail(`Uncaptured error:\n${ev.error.message}`); |
51 | 61 | }); |
52 | 62 | } |
53 | 63 |
|
54 | 64 | /** Fail by showing a console error, and dialog box if possible. */ |
55 | | -const fail = (() => { |
| 65 | +const fail: (message: string) => never = (() => { |
56 | 66 | type ErrorOutput = { show(msg: string): void }; |
57 | 67 |
|
58 | 68 | function createErrorOutput() { |
|
0 commit comments