mirror of
https://github.com/micropython/micropython.git
synced 2025-09-07 10:20:52 +02:00
This commit defines a new `JsException` exception type which is used on the Python side to wrap JavaScript errors. That's then used when a JavaScript Promise is rejected, and the reason is then converted to a `JsException` for the Python side to handle. This new exception is exposed as `jsffi.JsException`. Signed-off-by: Damien George <damien@micropython.org>
23 lines
484 B
JavaScript
23 lines
484 B
JavaScript
// Test await'ing on a JavaScript async function that throws a JavaScript Error.
|
|
|
|
const mp = await (await import(process.argv[2])).loadMicroPython();
|
|
|
|
globalThis.foo = async () => {
|
|
console.log(2);
|
|
throw Error("test");
|
|
};
|
|
|
|
await mp.runPythonAsync(`
|
|
import js, jsffi
|
|
print(1)
|
|
try:
|
|
await js.foo()
|
|
except jsffi.JsException as er:
|
|
error = er
|
|
print(error)
|
|
print(3)
|
|
`);
|
|
|
|
const error = mp.globals.get("error");
|
|
console.log(error instanceof Error, error.name, error.message);
|