Fix backtrace formatting in YPython::PyErrorHandler() #36
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: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 totraceback.format_exception()
. This method however expects that the value is already a valid exception object and fails quickly with anAttributeError
when that is not the case. This subsequently results in an unhandled error inYPython::PyErrorHandler()
and in aSystemError
when other Python/C API functions are invoked.The problem is fixed in the pull request by calling
PyErr_NormalizeException()
inYPython::PyErrorHandler()
to normalize the value to be an exception object. Additionally, a fix for a leaked reference to the traceback module in the same method is included.The pull request is for the SLE-15-SP2 branch. (I'm not sure if it is worth targeting any earlier branch.) A separate pull request for merging the changes to master will be made afterwards.
The following is a reproducer for the problem:
Test files:
main.rb
:PyTest.py
:native/native.c
:native/setup.py
:Steps to build and run the example:
Information logged in
/var/log/YaST2/y2log
:Fixed behavior: