Error: Already initialized. The `initWasm()` function can be used only once.
Closed this issue · 1 comments
Currently, when a worker already initialized the wasm modules, the initialization throws the error: Error: Already initialized. The
initWasm() function can be used only once.
.
This package already uses try ... catch
around the initialization functions, and does a console.error
when this happens, even though this indicates that it's safe to continue using the module. I would love this error not to show up when this happens, since this clutters our logs.
In my opinion, we should actually throw the error once it's not the Already initialized
error, and prevent initializing twice.
Suggested approach
- Store in global context / variable that a specific wasm module is already initialized or not.
- Prevent re-initializing by checking this
- Actually throw the error instead of
try ... catch
to make the system aware of actual errors other thanAlready initialized
occurring and we can catch it with e.g. error tracking software.
I'm willing to open a PR if this approach sounds good!
Hi @ItsWendell , thanks for raising this issue. Good point, the fact that resvg
throw
s that error can clutter the logs quickly.
I don't think setting up global variable is the best approach here as resvg
is already doing that with this variable:
var initialized = false;
And so I believe there won't be any performance benefit either by checking this ourselves.
So I think a simple matching of the error message, and then skipping the console.error
would suffice:
44e526f
And also, actually throw
ing the error sounds like a good idea to me, so that's been implemented as well.
3aac769
Anything else feel free to re-open this. Thanks!