Skip to content

Commit ed1680f

Browse files
dkuserdmitry-kanevgerzse
committed
Add details to the asyncio connection error message (#3211)
For asyncio connection errors, include the details in the error message, instead of only including the error code. Co-authored-by: dmitry.kanev <dmitry.kanev@dualbootpartners.com> Co-authored-by: Gabriel Erzse <gabriel.erzse@redis.com>
1 parent 511fda0 commit ed1680f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

redis/asyncio/connection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ def _error_message(self, exception: BaseException) -> str:
720720
else:
721721
return (
722722
f"Error {exception.args[0]} connecting to {host_error}. "
723-
f"{exception.args[0]}."
723+
f"{exception}."
724724
)
725725

726726

tests/test_asyncio/test_connection.py

+18
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,21 @@ async def test_connection_garbage_collection(request):
490490

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

0 commit comments

Comments
 (0)