Skip to content

Commit ccdf68a

Browse files
committed
wrap the last exception when reporting connect failure
fixes adafruit#113
1 parent 75ca1c5 commit ccdf68a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def _get_connect_socket(self, host, port, *, timeout=1):
252252

253253
sock = None
254254
retry_count = 0
255+
last_exception = None
255256
while retry_count < 5 and sock is None:
256257
retry_count += 1
257258

@@ -268,15 +269,20 @@ def _get_connect_socket(self, host, port, *, timeout=1):
268269

269270
try:
270271
sock.connect((connect_host, port))
271-
except MemoryError:
272+
except MemoryError as exc:
272273
sock.close()
273274
sock = None
274-
except OSError:
275+
last_exception = exc
276+
except OSError as exc:
275277
sock.close()
276278
sock = None
279+
last_exception = exc
277280

278281
if sock is None:
279-
raise RuntimeError("Repeated socket failures")
282+
if last_exception:
283+
raise RuntimeError("Repeated socket failures") from last_exception
284+
else:
285+
raise RuntimeError("Repeated socket failures")
280286

281287
self._backwards_compatible_sock = not hasattr(sock, "recv_into")
282288
return sock

0 commit comments

Comments
 (0)