diff options
| author | Damien George <damien@micropython.org> | 2024-05-06 12:26:20 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-05-06 14:04:13 +1000 |
| commit | 9da63a343e08c2a453ff32801bb0d9545e538497 (patch) | |
| tree | 8a90c07778095d5cc90cbaab3668332c99a82cd9 /tests | |
| parent | 9681a66c6b79a5f4721c74b756256336c47c9879 (diff) | |
webassembly/proxy_c: Reject promises with a PythonError instance.
The `reason` in a rejected promise should be an instance of `Error`. That
leads to better error messages on the JavaScript side.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ports/webassembly/run_python_async_error.mjs | 11 | ||||
| -rw-r--r-- | tests/ports/webassembly/run_python_async_error.mjs.exp | 5 |
2 files changed, 16 insertions, 0 deletions
diff --git a/tests/ports/webassembly/run_python_async_error.mjs b/tests/ports/webassembly/run_python_async_error.mjs new file mode 100644 index 000000000..ce4db0ff0 --- /dev/null +++ b/tests/ports/webassembly/run_python_async_error.mjs @@ -0,0 +1,11 @@ +// Test raising an exception in async Python code running in runPythonAsync, +// that the JavaScript-level promise is rejected with a PythonError. + +const mp = await (await import(process.argv[2])).loadMicroPython(); + +try { + await mp.runPythonAsync("await fail"); +} catch (error) { + console.log(error.name, error.type); + console.log(error.message); +} diff --git a/tests/ports/webassembly/run_python_async_error.mjs.exp b/tests/ports/webassembly/run_python_async_error.mjs.exp new file mode 100644 index 000000000..c77de4bb3 --- /dev/null +++ b/tests/ports/webassembly/run_python_async_error.mjs.exp @@ -0,0 +1,5 @@ +PythonError NameError +Traceback (most recent call last): + File "<stdin>", line 1, in <module> +NameError: name 'fail' isn't defined + |
