Handle worker loading errors with a callback in newCrossOriginWorker#539
Conversation
Added an optional error callback to newCrossOriginWorker to handle worker loading issues such as network errors or creation failures. Updated related channels to log errors and reject promises when worker initialization fails. This improves error handling and resilience in cross-origin worker loading.
|
This is additional fix, because this one #461 solves only a half problem. |
georgestagg
left a comment
There was a problem hiding this comment.
Thank you for debugging this issue further and providing this PR!
A minor nit is below, apologies for being overly picky about it.
src/webR/chan/channel-postmessage.ts
Outdated
| `${config.baseUrl}webr-worker.js`, | ||
| (worker: Worker) => initWorker(worker), | ||
| (error: Error) => { | ||
| console.error("Worker loading error:", error); |
There was a problem hiding this comment.
Do you mind if we remove the console.error() calls here and in the other channel implementations? If a user would like to write to the console they can do so by catching the WebRWorkerError rejection.
I don't mind the default console.error() emitted when onError is undefined.
There was a problem hiding this comment.
Sure, that makes sense — thanks for pointing it out!
I'll remove the console.error() calls from the channel implementations and rely on consumers to handle logging via the rejected WebRWorkerError, as you suggested.
I'll leave the default console.error() when onError is undefined.
Pushing an update shortly.
|
Don't mind the CI failure, I don't believe they're from your changes. I'm currently working on upgrading the Fortran infrastructure in another PR and it can't find the compiler because it has been renamed in the latest |
|
LGTM! Thanks! |
Added an optional error callback to newCrossOriginWorker to handle worker loading issues such as network errors or creation failures. Updated related channels to log errors and reject promises when worker initialization fails. This improves error handling and resilience in cross-origin worker loading.