Skip to content

Commit 15e51f7

Browse files
committed
Clarify timeout errors.
Specifically, not hiding the __cause__ of TimeoutError makes it visible when it happens while connecting to a proxy.
1 parent 3428820 commit 15e51f7

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

src/websockets/asyncio/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,9 @@ async def __await_impl__(self) -> ClientConnection:
511511
else:
512512
raise SecurityError(f"more than {MAX_REDIRECTS} redirects")
513513

514-
except TimeoutError:
514+
except TimeoutError as exc:
515515
# Re-raise exception with an informative error message.
516-
raise TimeoutError("timed out during handshake") from None
516+
raise TimeoutError("timed out during opening handshake") from exc
517517

518518
# ... = yield from connect(...) - remove when dropping Python < 3.10
519519

src/websockets/sync/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def handshake(
9090
self.protocol.send_request(self.request)
9191

9292
if not self.response_rcvd.wait(timeout):
93-
raise TimeoutError("timed out during handshake")
93+
raise TimeoutError("timed out while waiting for handshake response")
9494

9595
# self.protocol.handshake_exc is set when the connection is lost before
9696
# receiving a response, when the response cannot be parsed, or when the

src/websockets/sync/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def handshake(
128128
129129
"""
130130
if not self.request_rcvd.wait(timeout):
131-
raise TimeoutError("timed out during handshake")
131+
raise TimeoutError("timed out while waiting for handshake request")
132132

133133
if self.request is not None:
134134
with self.send_context(expected_state=CONNECTING):

tests/asyncio/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ async def test_timeout_during_handshake(self):
396396
self.fail("did not raise")
397397
self.assertEqual(
398398
str(raised.exception),
399-
"timed out during handshake",
399+
"timed out during opening handshake",
400400
)
401401

402402
async def test_connection_closed_during_handshake(self):
@@ -641,7 +641,7 @@ async def test_socks_proxy_connection_timeout(self):
641641
self.fail("did not raise")
642642
self.assertEqual(
643643
str(raised.exception),
644-
"timed out during handshake",
644+
"timed out during opening handshake",
645645
)
646646
self.assertNumFlows(0)
647647

tests/sync/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def test_timeout_during_handshake(self):
164164
self.fail("did not raise")
165165
self.assertEqual(
166166
str(raised.exception),
167-
"timed out during handshake",
167+
"timed out while waiting for handshake response",
168168
)
169169

170170
def test_connection_closed_during_handshake(self):

0 commit comments

Comments
 (0)