Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify pythonexc2js and add more careful error handling #1131

Merged
merged 5 commits into from
Jan 15, 2021

Conversation

hoodmane
Copy link
Member

I simplified the logic in pythonexc2js and implemented better error handling. I'm pretty sure that the original version actually always leaks the exception state because PyErr_Fetch takes ownership of type, value, and traceback but it never decref'd them.

Another issue with the original code is that it calls PyErr_Print() when the error indicator is unset. The docs say that PyErr_Print() may cause a fatal system error if called when the error indicator is unset:
https://docs.python.org/3/c-api/exceptions.html?highlight=pyerr_print#c.PyErr_PrintEx
This is not apparently true, looking at the source code of PyErr_Print, there is a guard check whether the error indicator is set, if not just does nothing. (This is really what it should do, not like it costs much to be reasonable.) Anyways, because the documented behavior of PyErr_Print says it triggers a fatal error in this case, I figure we ought to try to avoid calling it in that condition.

In future PRs I am hoping to update the error formatting to alternate between Python and javascript stack traces as the code crosses between languages and to implement fatal error trapping.

@hoodmane hoodmane changed the title Refactor pythonexc2js Simplify pythonexc2js and add more careful error handling Jan 14, 2021
src/core/python2js.c Outdated Show resolved Hide resolved
@dalcde dalcde merged commit 3adebcd into pyodide:master Jan 15, 2021
@hoodmane hoodmane deleted the refactor-pyexc2js branch January 15, 2021 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants