Skip to content

Commit 9f0758a

Browse files
dkuserdmitry-kanevgerzse
authored andcommitted
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]> Signed-off-by: Salvatore Mesoraca <[email protected]>
1 parent 6e43275 commit 9f0758a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

tests/test_asyncio/test_connection.py

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

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

valkey/asyncio/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ def _error_message(self, exception: BaseException) -> str:
814814
else:
815815
return (
816816
f"Error {exception.args[0]} connecting to {host_error}. "
817-
f"{exception.args[0]}."
817+
f"{exception}."
818818
)
819819

820820

0 commit comments

Comments
 (0)