PetterS / quickjs

Thin Python wrapper of https://bellard.org/quickjs/
https://github.com/bellard/QuickJS
MIT License
177 stars 19 forks source link

Fix #63 #66, supersede #67: Wrap Python exceptions into custom InternalPythonError #79

Open qwenger opened 2 years ago

qwenger commented 2 years ago

Fix #63, fix #66.

Supersedes #67. As proposed over there, this stores Python exception into a JS object rather than globally.

On the QuickJS side, the object uses as an opaque pointer to store the Python exception. On the JS side, the object has constructor InternalPythonError that extends InternalError and has the message property set to Python call failed. On the Python side, the exception type is JSPythonException, a subclass of JSException. Its __cause__ is set to the exception originally triggered, which is a pretty clean way to keep track of it.

The code has a few "not so nice" areas, but for which I did not find anything nicer:

qwenger commented 2 years ago

The check_memory.py script does not notice any issue (other than the spurious ones from threading, which also show up in master).

qwenger commented 2 years ago

One question is also whether we would like to expose the JS Internal(Python)Error via the JS(Python)Exception on the Python side, e.g. as an Object bound to JS(Python)Exception.raw.

Or better yet, make JSException subclass of Object and directly encapsulate the JS error inside it?