Skip to content

Commit

Permalink
Use a better exception type.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Aug 15, 2021
1 parent 4407d02 commit 2323512
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/websockets/legacy/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ async def ping(self, data: Optional[Data] = None) -> Awaitable[None]:
:raises ~websockets.exceptions.ConnectionClosed: when the
connection is closed
:raises ValueError: if another ping was sent with the same data and
:raises RuntimeError: if another ping was sent with the same data and
the corresponding pong wasn't received yet
"""
Expand All @@ -708,7 +708,7 @@ async def ping(self, data: Optional[Data] = None) -> Awaitable[None]:

# Protect against duplicates if a payload is explicitly set.
if data in self.pings:
raise ValueError("already waiting for a pong with the same data")
raise RuntimeError("already waiting for a pong with the same data")

# Generate a unique random payload otherwise.
while data is None or data in self.pings:
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ def test_canceled_ping(self):
def test_duplicate_ping(self):
self.loop.run_until_complete(self.protocol.ping(b"foobar"))
self.assertOneFrameSent(True, OP_PING, b"foobar")
with self.assertRaises(ValueError):
with self.assertRaises(RuntimeError):
self.loop.run_until_complete(self.protocol.ping(b"foobar"))
self.assertNoFrameSent()

Expand Down

0 comments on commit 2323512

Please sign in to comment.