Skip to content

Commit 0e413a0

Browse files
dkuserdmitry-kanevgerzse
authored andcommitted
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 <[email protected]> Co-authored-by: Gabriel Erzse <[email protected]>
1 parent c8feb77 commit 0e413a0

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
@@ -816,7 +816,7 @@ def _error_message(self, exception: BaseException) -> str:
816816
else:
817817
return (
818818
f"Error {exception.args[0]} connecting to {host_error}. "
819-
f"{exception.args[0]}."
819+
f"{exception}."
820820
)
821821

822822

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)