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

Fix backtrace formatting in YPython::PyErrorHandler() [Merge SLE-15-SP3 into master] #40

Merged
merged 11 commits into from
Aug 18, 2021

Conversation

dgdavid
Copy link
Member

@dgdavid dgdavid commented Aug 18, 2021

This PR replaces #39 after #38 was merged. It basically

lslezak and others added 10 commits April 21, 2020 16:31
An exception value returned by PyErr_Fetch() can be in certain
situations "unnormalized", which means the value does not have to be an
instance of the returned exception type. This typically happens when an
exception is set from a native library. For instance:
> PyObject *w = Py_BuildValue("(i,i)", 123, 456);
> PyErr_SetObject(NativeError, w);

The exception value is in this case a tuple object and not an instance
of NativeError, until the exception gets normalized.

Code in YPython::PyErrorHandler() passes an obtained exception value
directly to traceback.format_exception(). This method however expects
that the value is already a valid exception object and fails quickly
with an AttributeError when that is not the case. This subsequently
results in an unhandled error in YPython::PyErrorHandler() and in a
SystemError when other Python/C API functions are invoked.

The patch fixes the problem by calling PyErr_NormalizeException() in
YPython::PyErrorHandler() to normalize the value to be an exception
object.
PyImport_ImportModule("traceback") in YPython::PyErrorHandler() returns
a new reference. Add a call to Py_XDECREF() once the code is done with
the module to avoid leaking its reference.
Fix backtrace formatting in YPython::PyErrorHandler()
Fix backtrace formatting in YPython::PyErrorHandler() (Merge SLE-15-SP2 into SLE-15-SP3)
To have changes in sequence.
@dgdavid
Copy link
Member Author

dgdavid commented Aug 18, 2021

@petrpavlu I have created this one and closed #39 as commented at #39 (comment)

Hope you don't mind.

Copy link

@imobachgs imobachgs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a Python expert, but compared with #39 the changes look good to me. Thanks!

@dgdavid dgdavid merged commit 0313821 into master Aug 18, 2021
@dgdavid dgdavid deleted the sync-sp3-master branch August 18, 2021 10:06
@yast-bot
Copy link
Contributor

✔️ Public Jenkins job #24 successfully finished
✔️ Created OBS submit request #912871

@yast-bot
Copy link
Contributor

✔️ Internal Jenkins job #8 successfully finished
✔️ Created IBS submit request #248478

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.

None yet

6 participants