classification
Title: OSError: multiple exceptions should preserve the exception type if it is common
Type: Stage:
Components: asyncio Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: aymeric.augustin, nanjekyejoannah, r.david.murray, terry.reedy, yselivanov
Priority: normal Keywords:

Created on 2017-04-04 17:12 by r.david.murray, last changed 2019-04-18 22:51 by nanjekyejoannah.

Messages (4)
msg291126 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-04-04 17:12
create_connection will try multiple times to connect if there are multiple addresses returned by getaddrinfo.  If all connections file 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, looses 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.
msg291127 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-04-04 17:13
If all connections fail (not file :)
msg291288 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-04-07 19:47
I agree.  And if the sub-exceptions are different, prepend them to the messages in the OSError list.
msg340147 - (view) Author: Aymeric Augustin (aymeric.augustin) * Date: 2019-04-13 08:44
A very similar issue came up here: https://github.com/aaugustin/websockets/issues/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.
History
Date User Action Args
2019-04-18 22:51:16nanjekyejoannahsetnosy: + nanjekyejoannah
2019-04-13 08:44:08aymeric.augustinsetnosy: + aymeric.augustin
messages: + msg340147
2017-04-07 19:47:43terry.reedysetnosy: + terry.reedy
messages: + msg291288
2017-04-04 17:13:24r.david.murraysetmessages: + msg291127
2017-04-04 17:12:21r.david.murraycreate