Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refact(socket): corrections according to #562
- Rename `_` and `errs` variable names.
- Raise original error if a single one.
- Improve a bit error message, but still no Errno provided for when
multiple errors are included.
  • Loading branch information
ankostis committed Mar 17, 2017
commit b39d4b1c699e6bcb2ffcaf661bac6d0625e32b9e
14 changes: 8 additions & 6 deletions Lib/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,
"""

host, port = address
errs = []
errors = []
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
af, socktype, proto, canonname, sa = res
sock = None
Expand All @@ -713,13 +713,15 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,
sock.connect(sa)
return sock

except error as _:
errs.append(_)
except error as ex:
errors.append(ex)
if sock is not None:
sock.close()

if errs:
raise error("connection failed", errs)
nerr = len(errors)
if nerr == 1:
raise errors[0]
elif nerr > 1:
raise error("no connection possible due to %d errors" % nerr, errors)
else:
raise error("getaddrinfo returns an empty list")

Expand Down