-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom error message for Unix connect errors #4985
Conversation
This fixes #4984 |
I didn't feel like adding a unit-test was essential for this, but if you'd like me to add one, I can. |
Codecov Report
@@ Coverage Diff @@
## master #4985 +/- ##
==========================================
- Coverage 97.60% 97.58% -0.02%
==========================================
Files 43 43
Lines 8932 8941 +9
Branches 1406 1406
==========================================
+ Hits 8718 8725 +7
- Misses 95 97 +2
Partials 119 119
Continue to review full report at Codecov.
|
super().__init__(connection_key, os_error) | ||
|
||
@property | ||
def path(self) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd prefer this to be a pathlib.Path
instance that's only stringified when used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UnixConnector historically works with str
and has .path
string property.
I think we should keep the type for consistency.
Raised in :class:`aiohttp.connector.UnixConnector` if | ||
connection to unix socket can not be established. | ||
""" | ||
def __init__(self, path: str, connection_key: ConnectionKey, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be great to expect os.PathLike
/ pathlib.Path
for path
.
return self._path | ||
|
||
def __str__(self) -> str: | ||
return ('Cannot connect to unix socket {0.path} ssl:{1} [{2}]' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have two comments here:
- it's better to use named placeholders instead of positional ones
- you could do
self.path
in args like with other vars, otherwise, it looks inconsistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be great to add some integration tests + check how this works with abstract sockets.
Thanks for the comments @webknjaz . I'll update this tomorrow per your suggestions. I can add an integration test for a simple unix socket. However, I'm not sure exactly what you mean by "abstract sockets". Do you have some documentation on the topic you can refer me to? |
@zealws it's a Linux-only feature: https://utcc.utoronto.ca/~cks/space/blog/linux/SocketAbstractNamespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good in general.
@webknjaz please feel free to merge when ready.
I think the PR can be backported to 3.7 branch (label + bot works fine)
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Sviatoslav Sydorenko <[email protected]>
aiohttp/client_exceptions.py
Outdated
class UnixClientConnectorError(ClientConnectorError): | ||
"""Unix connector error. | ||
|
||
Raised in :class:`aiohttp.connector.UnixConnector` if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raised in :class:`aiohttp.connector.UnixConnector` if | |
Raised in aiohttp.UnixConnector if |
super().__init__(connection_key, os_error) | ||
|
||
@property | ||
def path(self) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UnixConnector historically works with str
and has .path
string property.
I think we should keep the type for consistency.
I'll fix the black formatting error by the next commit. |
💔 Backport was not successfulThe PR was attempted backported to the following branches:
|
* 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]>
* 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]>
* 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]>
* 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]>
What do these changes do?
UnixConnector client errors result in an error message which could be improved.
In particular, the error message notes the host/port pair, but for UnixConnector, the socket path is the primary way of identifying the connection, not host/port pair.
This is what the new error message looks like:
Full error and sample code in this gist
Are there changes in behavior for the user?
UnixConnector now raises
UnixClientConnectorError
instead ofClientConnectorError
.UnixClientConnectorError
is a subclass ofClientConnectorError
so anycatch ClientConnectorError
code should still function as expected.Related issue number
N/A
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.