-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Add option to get all errors from create_connection in an ExceptionGroup #74166
Comments
create_connection will try multiple times to connect if there are multiple addresses returned by getaddrinfo. If all connections fail it inspects the exceptions, and raises the first one if they are all equal. But since the addresses are often different (else why would we try multiple times?), the messages will usually be different. When the messages are different, the code raises an OSError with a list of the exceptions so the user can see them all. This, however, loses the information as to *what* kind of exception occurred (ie: ConnectioRefusedError, etc). I propose that if all of the exceptions raised are of the same subclass, that that subclass be raised with the multi-message list, rather than the base OSError. |
If all connections fail (not file :) |
I agree. And if the sub-exceptions are different, prepend them to the messages in the OSError list. |
A very similar issue came up here: python-websockets/websockets#593 When raising an exception that gathers multiple sub-exceptions, it would be nice to be able to iterate the exception to access the sub-exceptions. |
The feature request reminds me of python-trio/trio#611. Nathaniel and Yury have been discussing the idea of a MultiError handler for a while. |
Do we want to do this with ExceptionGroup for 3.11? |
Perhaps, though we’d have to add a flag to enable that behavior, since raising EG would be a backwards incompatible change. |
Would it be possible to mark the new all_errors parameter as a keyword-only parameter? |
I ran into this while using asyncio.create_connection, which is also what was being used in the linked issue above in the websockets library. The referenced code commit fixing this issue is for sockets.py, however, not for the asyncio version. What do you think of adding to asyncio.base_events.py create_connection, using same keyword arg
Here's my code that uses it:
|
@pamelafox Go ahead and create a new issue and PR for this. It's too late for 3.11, but it could go into 3.12 if the asyncio maintainers agree. Though, you should check all_errors before len(exceptions). If all_errors then you should always raise an ExceptionGroup, even if it's only of size 1. |
@iritkatriel Okay, sounds good, I'll work on that. And yeah I realized after posting that diff that it needs to go earlier. Thank you! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: