Skip to content

Commit 57af285

Browse files
dkuserdmitry-kanevgerzse
authored
Add details to the asyncio connection error message (redis#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 ee2a98b commit 57af285

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

823823

tests/test_asyncio/test_connection.py

+18
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)