Skip to content

Commit 8b2d295

Browse files
committed
Add details to the asyncio connection error message
1 parent 07fc339 commit 8b2d295

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

redis/asyncio/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ def _error_message(self, exception: BaseException) -> str:
805805
else:
806806
return (
807807
f"Error {exception.args[0]} connecting to {host_error}. "
808-
f"{exception.args[0]}."
808+
f"{exception}."
809809
)
810810

811811

tests/test_asyncio/test_connection.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,21 @@ async def test_connection_garbage_collection(request):
491491

492492
await client.aclose()
493493
await pool.aclose()
494+
495+
496+
@pytest.mark.parametrize(
497+
"error, expected_message",
498+
[
499+
(OSError(), "Error connecting to localhost:6379. Connection reset by peer"),
500+
(OSError(12), "Error connecting to localhost:6379. 12."),
501+
(
502+
OSError(12, "Some Error"),
503+
"Error 12 connecting to localhost:6379. [Errno 12] Some Error.",
504+
),
505+
],
506+
)
507+
async def test_connect_error_message(error, expected_message):
508+
"""Test that the _error_message function formats errors correctly"""
509+
conn = Connection()
510+
error_message = conn._error_message(error)
511+
assert error_message == expected_message

0 commit comments

Comments
 (0)