Better logging of unhandled Python 3.11 ExceptionGroups #161
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.
Python 3.11 introduced exception groups (the
{Base,}ExceptionGroup
classes) to better handle situations where async (and other) code may raise multiple exceptions that need to be propagated and handled/logged together.Unfortunately the Lambda Python RIC's logging of unhandled exceptions performs rather poorly when encountering such exception groups. I have a lambda function that is implemented with async Python code (using the
trio
framework, but that's tangential, and the same problem could occur using the stdlibasyncio
framework), and I've been running into situations where the lambda function fails for a variety of reasons (such as being unable to connect to one of its dependency services), and all I get in the response is:The fact that only the top-level
ExceptionGroup
object is included in the output has been incredibly frustrating because it obscures the true cause of the failure.As
asyncio
matures, this situation will become increasingly common (though likely never exactly become a mainstream problem). I believe you should find some way of including information about the exceptions nested inside the exception group. In this PR I'm proposing a simple change that concatenates all nested exception messages for inclusion in theerrorMessage
field, but if you prefer a more sophisticated solution, feel free to use my simple change as a starting point.Ideally the structure generated by the
make_error
function would be overhauled to account for the fact that as of Python 3.11, exceptions can now be trees of exceptions.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.