Skip to content

Commit

Permalink
Add details to the asyncio connection error message
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-kanev committed Apr 20, 2024
1 parent 07fc339 commit 8b2d295
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,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}."
)


Expand Down
18 changes: 18 additions & 0 deletions tests/test_asyncio/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8b2d295

Please sign in to comment.