|
50 | 50 | requirements: requirements ?? [],
|
51 | 51 | sharedWorkerMode: sharedWorkerMode ?? false
|
52 | 52 | });
|
| 53 | +
|
| 54 | + const dispatch = createEventDispatcher(); |
| 55 | +
|
| 56 | + worker_proxy.addEventListener("modules-auto-loaded", (event) => { |
| 57 | + dispatch("modules-auto-loaded", (event as CustomEvent).detail); |
| 58 | + }); |
| 59 | + worker_proxy.addEventListener("stdout", (event) => { |
| 60 | + dispatch("stdout", (event as CustomEvent).detail); |
| 61 | + }); |
| 62 | + worker_proxy.addEventListener("stderr", (event) => { |
| 63 | + dispatch("stderr", (event as CustomEvent).detail); |
| 64 | + }); |
| 65 | + worker_proxy.addEventListener("initialization-error", (event) => { |
| 66 | + error = (event as CustomEvent).detail; |
| 67 | + dispatch("initialization-error", (event as CustomEvent).detail); |
| 68 | + }); |
| 69 | + worker_proxy.addEventListener("python-error", (event) => { |
| 70 | + error = (event as CustomEvent).detail; |
| 71 | + dispatch("python-error", (event as CustomEvent).detail); |
| 72 | + }); |
53 | 73 | onDestroy(() => {
|
54 | 74 | worker_proxy.terminate();
|
55 | 75 | });
|
|
90 | 110 | worker_proxy.install.bind(worker_proxy)
|
91 | 111 | );
|
92 | 112 |
|
93 |
| - worker_proxy.addEventListener("initialization-error", (event) => { |
94 |
| - error = (event as CustomEvent).detail; |
95 |
| - }); |
96 |
| -
|
97 |
| - const dispatch = createEventDispatcher(); |
98 |
| -
|
99 |
| - worker_proxy.addEventListener("modules-auto-loaded", (event) => { |
100 |
| - dispatch("modules-auto-loaded", (event as CustomEvent).detail); |
101 |
| - }); |
102 |
| -
|
103 | 113 | // Internally, the execution of `runPythonCode()` or `runPythonFile()` is queued
|
104 | 114 | // and its promise will be resolved after the Pyodide is loaded and the worker initialization is done
|
105 | 115 | // (see the await in the `onmessage` callback in the webworker code)
|
106 | 116 | // So we don't await this promise because we want to mount the `Index` immediately and start the app initialization asynchronously.
|
107 | 117 | if (code != null) {
|
108 |
| - worker_proxy.runPythonCode(code); |
| 118 | + worker_proxy.runPythonCode(code).catch((err) => { |
| 119 | + dispatch("init-code-run-error", err); |
| 120 | + }); |
109 | 121 | } else if (entrypoint != null) {
|
110 |
| - worker_proxy.runPythonFile(entrypoint); |
| 122 | + worker_proxy.runPythonFile(entrypoint).catch((err) => { |
| 123 | + dispatch("init-file-run-error", err); |
| 124 | + }); |
111 | 125 | } else {
|
112 | 126 | throw new Error("Either code or entrypoint must be provided.");
|
113 | 127 | }
|
|
157 | 171 | >
|
158 | 172 | {#key index_component_key}
|
159 | 173 | {#if error}
|
160 |
| - <ErrorDisplay {error} is_embed /> |
| 174 | + <ErrorDisplay |
| 175 | + {error} |
| 176 | + {is_embed} |
| 177 | + height={initial_height} |
| 178 | + {container} |
| 179 | + {version} |
| 180 | + on:clear_error={() => { |
| 181 | + error = null; |
| 182 | + }} |
| 183 | + /> |
161 | 184 | {:else}
|
162 | 185 | <Index
|
163 | 186 | space={null}
|
|
182 | 205 | {:else}
|
183 | 206 | {#key index_component_key}
|
184 | 207 | {#if error}
|
185 |
| - <ErrorDisplay {error} {is_embed} /> |
| 208 | + <ErrorDisplay |
| 209 | + {error} |
| 210 | + {is_embed} |
| 211 | + height={initial_height} |
| 212 | + {container} |
| 213 | + {version} |
| 214 | + on:clear_error={() => { |
| 215 | + error = null; |
| 216 | + }} |
| 217 | + /> |
186 | 218 | {:else}
|
187 | 219 | <Index
|
188 | 220 | space={null}
|
|
0 commit comments