Skip to content

Add details to the asyncio connection error message #3211

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

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion redis/asyncio/connection.py
Original file line number Diff line number Diff line change
@@ -817,7 +817,7 @@ def _error_message(self, exception: BaseException) -> str:
else:
return (
f"Error {exception.args[0]} connecting to {host_error}. "
f"{exception.args[0]}."
f"{exception}."
)


18 changes: 18 additions & 0 deletions tests/test_asyncio/test_connection.py
Original file line number Diff line number Diff line change
@@ -491,3 +491,21 @@ async def test_connection_garbage_collection(request):

await client.aclose()
await pool.aclose()


@pytest.mark.parametrize(
"error, expected_message",
[
(OSError(), "Error connecting to localhost:6379. Connection reset by peer"),
(OSError(12), "Error connecting to localhost:6379. 12."),
(
OSError(12, "Some Error"),
"Error 12 connecting to localhost:6379. [Errno 12] Some Error.",
),
],
)
async def test_connect_error_message(error, expected_message):
"""Test that the _error_message function formats errors correctly"""
conn = Connection()
error_message = conn._error_message(error)
assert error_message == expected_message