wasmerio / wasmer

🚀 The leading Wasm Runtime supporting WASIX and WASI
https://wasmer.io
MIT License
18.91k stars 811 forks source link

c-api shows no error message when failing instantiation, how to check what is wrong? #4581

Open MrHate opened 6 months ago

MrHate commented 6 months ago

Summary

I was trying wasmer with c-api (static link with libwasmer.a generated from make build-capi) but kept failing instantiation. However, the only error information I got was the return value from wasm_instance_new. I don't really realize what was actually wrong with my program, wondering if there is a way to extract some helpful information relavant to my mistake?

syrusakbary commented 6 months ago

Would it be possible to have the program so we can investigate a bit more how we can improve the error messages?

MrHate commented 6 months ago

For example, I have my code using wasmer with c-api like the following:

...
instance = wasm_instance_new(store, module, &imports, NULL);
if (!instance) {
  fprintf(stderr, "Err instantiating.\n");
  goto init_fail;
}
...

If any of the Wasm application's required imports is missing during the instantiation, this code fails with a NULL return value for instance, but nothing more printed to explain the error.

To figure out what is actually wrong with my code I had to add prints to each exception handler here: https://github.com/wasmerio/wasmer/blob/master/lib/c-api/src/wasm_c_api/instance.rs#L59.