Skip to content

Commit f813def

Browse files
authored
Merge pull request adafruit#118 from vladak/connect_failures_exception
wrap the last exception when reporting repeated connect failures
2 parents 42f13a8 + 6d94eee commit f813def

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ def _get_connect_socket(self, host, port, *, timeout=1):
266266

267267
sock = None
268268
retry_count = 0
269+
last_exception = None
269270
while retry_count < 5 and sock is None:
270271
retry_count += 1
271272

@@ -282,14 +283,19 @@ def _get_connect_socket(self, host, port, *, timeout=1):
282283

283284
try:
284285
sock.connect((connect_host, port))
285-
except MemoryError:
286+
except MemoryError as exc:
286287
sock.close()
287288
sock = None
288-
except OSError:
289+
last_exception = exc
290+
except OSError as exc:
289291
sock.close()
290292
sock = None
293+
last_exception = exc
291294

292295
if sock is None:
296+
if last_exception:
297+
raise RuntimeError("Repeated socket failures") from last_exception
298+
293299
raise RuntimeError("Repeated socket failures")
294300

295301
self._backwards_compatible_sock = not hasattr(sock, "recv_into")

0 commit comments

Comments
 (0)