-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Since v4.0, module instantiation errors can’t be caught because two errors are thrown if MODULARIZE=1 #24415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@sbc100 you’ve worked on this code recently—do you have any thoughts on this? |
Thanks for debugging the issue @FelixNumworks. I certainly believe there is a fix like this needed here. (By the way you say "top-level await" but IIUC that await you are refering to is the one inside the |
Yes I meant top-level in the factory function, not in the actual sense, sorry ^^" This |
In `MODUALRIZE` mode we always do `await createWasm` so means any uncaught exceptions in `createWasm` will be thrown there, before `readyPromise` is event returned from the factory function. Fixes: emscripten-core#24415
I have a fix in flight: #24418. I'm still working on test for it. |
In `MODUALRIZE` mode we always do `await createWasm` so means any uncaught exceptions in `createWasm` will be thrown there, before `readyPromise` is event returned from the factory function. Fixes: emscripten-core#24415
In `MODUALRIZE` mode we always do `await createWasm` so means any uncaught exceptions in `createWasm` will be thrown there, before `readyPromise` is event returned from the factory function. Fixes: emscripten-core#24415
In `MODUALRIZE` mode we always do `await createWasm` so means any uncaught exceptions in `createWasm` will be thrown there, before `readyPromise` is event returned from the factory function. Fixes: emscripten-core#24415
If are you able could you confirm whether #24418 fixes the issue? |
I tested it, it works perfectly :) |
Just as a side note, since we discussed this subject earlier, |
The goal is certainly to make embind work with |
In `MODUALRIZE` mode we always do `await createWasm` before we return the readyPromise. This means there is no need to call `readyPromiseReject` inside of createWasm. Furthermore, we can completely avoid creating the ready promise if we don't need it and make all the resolve/reject sites call the resolve/reject handlers conditionally. Fixes: #24415
I added support fairly recently for embind and instance mode, let me know if you run into anything. |
Uh oh!
There was an error while loading. Please reload this page.
Version of emscripten/emsdk: 4.0.8 (bug introduced in 4.0.0)
Description
I'm compiling with the
MODULARIZE=1
flag and using code like the following to instantiate the module in js:Before version 4.0, everything worked as expected: if the
.wasm
file failed to load, the error was caught and handled.Since version 4.0, however, when the
.wasm
fetch fails, two errors are thrown in sequence. I can only catch one, but another one is thrown later and can't be caught because thecatch
block has already run.Cause
This issue appears to originate from the following line in
Module.js
:This line is generated by this one:
emscripten/tools/emscripten.py
Lines 1047 to 1052 in fe95793
This was introduced by this PR #23157
Here’s a minimal reproduction of the
Module.js
structure:So
error2
is caught by user code, buterror1
is thrown after the fact and cannot be intercepted, leading to an unhandled rejection or uncaught error.Suggested Fix
Modifying the
Module.js
file this way fixes the problem:This avoids throwing a second error, but it’s obviously not ideal.
The core issue is mixing a top-level
await
with a promise (readyPromise
) that is also being rejected separately. This leads to two separate error flows. In my opinion, the code should use either top-levelawait
or a returned/rejected promise—not both.The text was updated successfully, but these errors were encountered: