Skip to content

Commit

Permalink
[3.8] Custom error message for Unix connect errors (#4985) (#5264)
Browse files Browse the repository at this point in the history
* Custom error message for Unix connect errors

* Update aiohttp/client_exceptions.py

Co-authored-by: Sviatoslav Sydorenko <[email protected]>

Co-authored-by: Andrew Svetlov <[email protected]>
Co-authored-by: Sviatoslav Sydorenko <[email protected]>.
(cherry picked from commit e19c79e)

Co-authored-by: Zeal Wierslee <[email protected]>

Co-authored-by: Zeal Wierslee <[email protected]>
  • Loading branch information
asvetlov and zealws authored Nov 21, 2020
1 parent c7988ad commit e55174a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/4984.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added a new exception type for Unix socket client errors which provides a more useful error message.
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ Young-Ho Cha
Yuriy Shatrov
Yury Selivanov
Yusuke Tsutsumi
Yuval Ofir
Zeal Wierslee
Zlatan Sičanica
Марк Коренберг
Семён Марьясин
23 changes: 23 additions & 0 deletions aiohttp/client_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,29 @@ class ClientProxyConnectionError(ClientConnectorError):
"""


class UnixClientConnectorError(ClientConnectorError):
"""Unix connector error.
Raised in :py:class:`aiohttp.connector.UnixConnector`
if connection to unix socket can not be established.
"""

def __init__(
self, path: str, connection_key: ConnectionKey, os_error: OSError
) -> None:
self._path = path
super().__init__(connection_key, os_error)

@property
def path(self) -> str:
return self._path

def __str__(self) -> str:
return "Cannot connect to unix socket {0.path} ssl:{1} [{2}]".format(
self, self.ssl if self.ssl is not None else "default", self.strerror
)


class ServerConnectionError(ClientConnectionError):
"""Server connection errors."""

Expand Down
3 changes: 2 additions & 1 deletion aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
ClientHttpProxyError,
ClientProxyConnectionError,
ServerFingerprintMismatch,
UnixClientConnectorError,
cert_errors,
ssl_errors,
)
Expand Down Expand Up @@ -1194,7 +1195,7 @@ async def _create_connection(
self._factory, self._path
)
except OSError as exc:
raise ClientConnectorError(req.connection_key, exc) from exc
raise UnixClientConnectorError(self.path, req.connection_key, exc) from exc

return cast(ResponseHandler, proto)

Expand Down
4 changes: 4 additions & 0 deletions docs/client_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,10 @@ Connection errors

Derived from :exc:`ClientConnectorError`

.. class:: UnixClientConnectorError

Derived from :exc:`ClientConnectorError`

.. class:: ServerConnectionError

Derived from :exc:`ClientConnectionError`
Expand Down

0 comments on commit e55174a

Please sign in to comment.