Skip to content

Commit

Permalink
httpcore/backends/trio: map OSError exceptions (#543)
Browse files Browse the repository at this point in the history
The underlying socket implementations can raise OSError for situations
such as `getaddrinfo` failing to resolve an address.

Previously, these errors would not be mapped to httpcore exception types
for the trio backend.

Now, map OSError exceptions in the trio backend to ConnectError.

This will make trio consistent with the asyncio backend.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
  • Loading branch information
vfazio committed May 11, 2022
1 parent 1bf9cf2 commit 15d8093
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions httpcore/backends/trio.py
Expand Up @@ -111,6 +111,7 @@ async def connect_tcp(
exc_map = {
trio.TooSlowError: ConnectTimeout,
trio.BrokenResourceError: ConnectError,
OSError: ConnectError,
}
# Trio supports 'local_address' from 0.16.1 onwards.
# We only include the keyword argument if a local_address
Expand All @@ -130,6 +131,7 @@ async def connect_unix_socket(
exc_map = {
trio.TooSlowError: ConnectTimeout,
trio.BrokenResourceError: ConnectError,
OSError: ConnectError,
}
with map_exceptions(exc_map):
with trio.fail_after(timeout_or_inf):
Expand Down

0 comments on commit 15d8093

Please sign in to comment.