Skip to content

Commit

Permalink
disambiguate asyncio.TimeoutError from OSError
Browse files Browse the repository at this point in the history
in 3.11 asyncio.TimeoutError became an OSError
  • Loading branch information
graingert committed Aug 9, 2022
1 parent 37fa089 commit e5789af
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ async def _request(
raise
except ClientError:
raise
except asyncio.TimeoutError:
raise
except OSError as exc:
raise ClientOSError(*exc.args) from exc

Expand Down
2 changes: 2 additions & 0 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ async def write_bytes(
await writer.write(chunk) # type: ignore[arg-type]

await writer.write_eof()
except asyncio.TimeoutError:
raise
except OSError as exc:
new_exc = ClientOSError(
exc.errno, "Can not write request body for %s" % self.url
Expand Down
10 changes: 10 additions & 0 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,8 @@ async def _wrap_create_connection(
raise ClientConnectorCertificateError(req.connection_key, exc) from exc
except ssl_errors as exc:
raise ClientConnectorSSLError(req.connection_key, exc) from exc
except asyncio.TimeoutError:
raise
except OSError as exc:
raise client_error(req.connection_key, exc) from exc

Expand Down Expand Up @@ -1048,6 +1050,8 @@ async def _start_tls_connection(
raise ClientConnectorCertificateError(req.connection_key, exc) from exc
except ssl_errors as exc:
raise ClientConnectorSSLError(req.connection_key, exc) from exc
except asyncio.TimeoutError:
raise
except OSError as exc:
raise client_error(req.connection_key, exc) from exc
except TypeError as type_err:
Expand Down Expand Up @@ -1099,6 +1103,8 @@ def drop_exception(fut: "asyncio.Future[List[Dict[str, Any]]]") -> None:

host_resolved.add_done_callback(drop_exception)
raise
except asyncio.TimeoutError:
raise
except OSError as exc:
# in case of proxy it is not ClientProxyConnectionError
# it is problem of resolving proxy ip itself
Expand Down Expand Up @@ -1292,6 +1298,8 @@ async def _create_connection(
_, proto = await self._loop.create_unix_connection(
self._factory, self._path
)
except asyncio.TimeoutError:
raise
except OSError as exc:
raise UnixClientConnectorError(self.path, req.connection_key, exc) from exc

Expand Down Expand Up @@ -1357,6 +1365,8 @@ async def _create_connection(
await asyncio.sleep(0)
# other option is to manually set transport like
# `proto.transport = trans`
except asyncio.TimeoutError:
raise
except OSError as exc:
raise ClientConnectorError(req.connection_key, exc) from exc

Expand Down

0 comments on commit e5789af

Please sign in to comment.