Skip to content

Commit

Permalink
Custom error message for Unix connect errors (#4985)
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]>
  • Loading branch information
3 people authored Nov 21, 2020
1 parent 213be22 commit e19c79e
Show file tree
Hide file tree
Showing 5 changed files with 31 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.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ Yuriy Shatrov
Yury Selivanov
Yusuke Tsutsumi
Yuval Ofir
Zeal Wierslee
Zlatan Sičanica
Марк Коренберг
Семён Марьясин
21 changes: 21 additions & 0 deletions aiohttp/client_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,27 @@ 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
5 changes: 4 additions & 1 deletion aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
ClientHttpProxyError,
ClientProxyConnectionError,
ServerFingerprintMismatch,
UnixClientConnectorError,
cert_errors,
ssl_errors,
)
Expand Down Expand Up @@ -1162,7 +1163,9 @@ 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 e19c79e

Please sign in to comment.