micropython-wasm
micropython-wasm copied to clipboard
Silent failure on python exceptions
I don't know how much this is to do with your code or Emscripten, but if your python code raises an exception, the do_str
promise never resolves. Eg:
import mp_js from 'micropython'
async () => {
await mp_js.init(64 * 1024)
const stdout = await mp_js.do_str(`invalid syntax`)
console.log(stdout) // <-- this never logs and no exception is raised
}();
This makes it very difficult to debug what could be going wrong. It would be great if python exceptions were accessible in some way, even if just logged to console, and the promise rejected.
Unfortunately thats come from the original micropython port, maybe due to this https://emscripten.org/docs/optimizing/Optimizing-Code.html#other-optimization-issues.
In general, because wasm is a target compilation every feature that we need to use on the resulting bytecode will affect the file size (for example, this repo uses emterpreter for async sleep). Thats why Im currently moving to RPython (its a statically compiled python) because it is able to detect compilation error rather than handling runtime errors.
Although like that, Im open to ideas to fix this issue.
Btw, in your repo:
The code appears to be trying to check if we're running with webpack or with node but webpack is still trying to require the things on the node code path. You can get around this by finding each line webpack's complaining about, finding the preceding if condition that checks for webpackJsonp or window or similar and adding typeof __webpack_require__ !== 'function' && to it.
I will add this fix, thanks for contributing!
Interesting, thanks for the extra context. And thanks for doing all the hard work so I could PoC python in the browser in only a couple hours! It was super cool to be able to do, even if it's still a little rough around the edges.
@tessereth you would probably need to intercept uncaught exception in some way at micropython vm level and then pass them explicitly and check them with js, maybe related https://github.com/micropython/micropython/issues/3217