[issue23188] Exception chaining should trigger for non-normalised exceptions
Nick Coghlan added the comment: Ah, confusion between exception has been raised and we're in an active exception handler is almost certainly what is happening. In both issue 22906 and my previous codec exception wrapping work, we're still in the C code that raised the exception, *before* we make it back to the eval loop and any Python level exception handling. So I think that's the distinction we need to ensure is documented, and potentially a new public helper function provided - if you're in a Python level exception handler, then exception context chaining will be handled automatically for you in PyErr_SetObject, but if you're still in C code and haven't made it back to the eval loop after raising an exception, then you're going to have to do any exception chaining explicitly. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23188 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23188] Exception chaining should trigger for non-normalised exceptions
Antoine Pitrou added the comment: The interesting discovery I made while reviewing the patch for issue 22906 is that there apparently *is* implicit chaining support in PyErr_SetObject Indeed, there is, and it should work properly (AFAIR there was quite a bit of debugging to make this work). Also, note that normalizing is already handled. I'm not sure what you're witnessing that doesn't work as expected. I suspect that you may be confusing an exception has been caught (and is ready to be chained from) with an exception has been raised (i.e. PyErr_Occurred() is true). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23188 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23188] Exception chaining should trigger for non-normalised exceptions
Nick Coghlan added the comment: The interesting discovery I made while reviewing the patch for issue 22906 is that there apparently *is* implicit chaining support in PyErr_SetObject: https://hg.python.org/cpython/file/default/Python/errors.c#l70 Chris indicates that it doesn't seem to be triggering for his patch, though (even after normalising and then restoring the exception state), and I haven't fully dug into why yet. Preliminary explorations show that the last two functional modifications were a fix for a crash bug in issue 3611, and Antoine's original implementation of exception chaining in issue 3108. I've added Antoine to the nosy list, as my main takeaway at the moment is that I *don't* currently understand what's going on with the exception chaining, and I'd like to before we merge the PEP 479 patch. -- nosy: +pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23188 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23188] Exception chaining should trigger for non-normalised exceptions
Nick Coghlan added the comment: The documentation of PyErr_SetObject, PyErr_SetString et al should also be updated to mention exception chaining. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23188 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23188] Exception chaining should trigger for non-normalised exceptions
Nick Coghlan added the comment: After looking into this further, PyErr_SetObject (and other APIs like PyErr_SetString which call that internally) aim to handle the chaining automatically, but they don't handle exceptions which haven't been normalized yet. PyErr_SetObject should probably normalise the exception at the start of the call f ithe exception type is set on the thread state, but not the exception value. -- title: Convert _PyErr_ChainExceptions to a public API - Exception chaining should trigger for non-normalised exceptions type: enhancement - behavior ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23188 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23188] Exception chaining should trigger for non-normalised exceptions
Nick Coghlan added the comment: Thinking about it a bit further, I suspect implicit normalisation of chained exceptions could cause problems when we only want to set __cause__ without setting __context__ (e.g. codec exception chaining). I'm going to ponder this one for a while, but happy to hear anyone else's feedback. At the very least, I think the C API docs could use a bit more clarity on the intricacies of C level exception chaining. -- assignee: - ncoghlan ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23188 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue23188] Exception chaining should trigger for non-normalised exceptions
Serhiy Storchaka added the comment: _PyErr_ChainExceptions() was added because exceptions raised in C code are not implicitly chained. The code for explicit chaining is error prone, so it was extracted in separate function. Even with _PyErr_ChainExceptions() chaining exceptions look complex. May be implicit chaining all exceptions would be better. -- nosy: +serhiy.storchaka ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23188 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com