Skip to content

Commit

Permalink
wrap real OSError asyncio.TimeoutErrors in a ClientOSError
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Aug 9, 2022
1 parent e5789af commit 74340cb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,9 @@ async def _request(
raise
except ClientError:
raise
except asyncio.TimeoutError:
raise
except OSError as exc:
if exc.errno is None and isinstance(exc, asyncio.TimeoutError):
raise
raise ClientOSError(*exc.args) from exc

self._cookie_jar.update_cookies(resp.cookies, resp.url)
Expand Down
17 changes: 9 additions & 8 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,15 +536,16 @@ 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
)
new_exc.__context__ = exc
new_exc.__cause__ = exc
protocol.set_exception(new_exc)
if exc.errno is None and isinstance(exc, asyncio.TimeoutError):
protocol.set_exception(exc)
else:
new_exc = ClientOSError(
exc.errno, "Can not write request body for %s" % self.url
)
new_exc.__context__ = exc
new_exc.__cause__ = exc
protocol.set_exception(new_exc)
except asyncio.CancelledError as exc:
if not conn.closed:
protocol.set_exception(exc)
Expand Down
20 changes: 10 additions & 10 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,9 @@ 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:
if exc.errno is None and isinstance(exc, asyncio.TimeoutError):
raise
raise client_error(req.connection_key, exc) from exc

def _warn_about_tls_in_tls(
Expand Down Expand Up @@ -1050,9 +1050,9 @@ 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:
if exc.errno is None and isinstance(exc, asyncio.TimeoutError):
raise
raise client_error(req.connection_key, exc) from exc
except TypeError as type_err:
# Example cause looks like this:
Expand Down Expand Up @@ -1103,9 +1103,9 @@ 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:
if exc.errno is None and isinstance(exc, asyncio.TimeoutError):
raise
# in case of proxy it is not ClientProxyConnectionError
# it is problem of resolving proxy ip itself
raise ClientConnectorError(req.connection_key, exc) from exc
Expand Down Expand Up @@ -1298,9 +1298,9 @@ async def _create_connection(
_, proto = await self._loop.create_unix_connection(
self._factory, self._path
)
except asyncio.TimeoutError:
raise
except OSError as exc:
if exc.errno is None and isinstance(exc, asyncio.TimeoutError):
raise
raise UnixClientConnectorError(self.path, req.connection_key, exc) from exc

return cast(ResponseHandler, proto)
Expand Down Expand Up @@ -1365,9 +1365,9 @@ 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:
if exc.errno is None and isinstance(exc, asyncio.TimeoutError):
raise
raise ClientConnectorError(req.connection_key, exc) from exc

return cast(ResponseHandler, proto)

0 comments on commit 74340cb

Please sign in to comment.