Skip to content

Commit c7bb14a

Browse files
authored
Remove timeout breadcrumb from ConnectionLostError (#20)
1 parent 69f727e commit c7bb14a

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

stompman/connection.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ async def read_frame_of_type(self, type_: type[FrameT]) -> FrameT:
8383
return frame
8484

8585

86+
@contextmanager
87+
def _reraise_connection_lost(*causes: type[Exception]) -> Generator[None, None, None]:
88+
try:
89+
yield
90+
except causes as exception:
91+
raise ConnectionLostError from exception
92+
93+
8694
@dataclass
8795
class Connection(AbstractConnection):
8896
connection_parameters: ConnectionParameters
@@ -102,24 +110,17 @@ async def connect(self) -> bool:
102110
return False
103111
return True
104112

105-
@contextmanager
106-
def _reraise_connection_lost(self, *causes: type[Exception]) -> Generator[None, None, None]:
107-
try:
108-
yield
109-
except causes as exception:
110-
raise ConnectionLostError(self.read_timeout) from exception
111-
112113
async def close(self) -> None:
113114
self.writer.close()
114-
with self._reraise_connection_lost(ConnectionError):
115+
with _reraise_connection_lost(ConnectionError):
115116
await self.writer.wait_closed()
116117

117118
def write_heartbeat(self) -> None:
118119
return self.writer.write(NEWLINE)
119120

120121
async def write_frame(self, frame: AnyClientFrame) -> None:
121122
self.writer.write(dump_frame(frame))
122-
with self._reraise_connection_lost(ConnectionError):
123+
with _reraise_connection_lost(ConnectionError):
123124
await self.writer.drain()
124125

125126
async def _read_non_empty_bytes(self) -> bytes:
@@ -133,7 +134,7 @@ async def read_frames(self) -> AsyncGenerator[AnyServerFrame, None]:
133134
parser = Parser()
134135

135136
while True:
136-
with self._reraise_connection_lost(ConnectionError, TimeoutError):
137+
with _reraise_connection_lost(ConnectionError, TimeoutError):
137138
raw_frames = await asyncio.wait_for(self._read_non_empty_bytes(), timeout=self.read_timeout)
138139

139140
for frame in cast(Iterator[AnyServerFrame], parser.load_frames(raw_frames)):

stompman/errors.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,4 @@ class FailedAllConnectAttemptsError(Error):
3131

3232

3333
@dataclass
34-
class ConnectionLostError(Error):
35-
timeout: int
34+
class ConnectionLostError(Error): ...

0 commit comments

Comments
 (0)