From 3622dc4ab6aee33a651247ce36bebf2715b6003a Mon Sep 17 00:00:00 2001 From: Hanne Moa Date: Wed, 31 Jan 2024 09:10:50 +0100 Subject: [PATCH] Catch BrokenPipeError on socket send If we lose connection while sending data to the server, a BrokenPipeError is sent. It was uncaught. --- src/zinolib/ritz.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/zinolib/ritz.py b/src/zinolib/ritz.py index 7346c5f..321dac3 100644 --- a/src/zinolib/ritz.py +++ b/src/zinolib/ritz.py @@ -371,7 +371,10 @@ def _request(self, command: bytes, recv_buffer=4096, **_): delimiter = bytes(self.DELIMITER, 'ascii') if not command.endswith(delimiter): command += delimiter - self._sock.send(command) + try: + self._sock.send(command) + except BrokenPipeError as e: + raise NotConnectedError(f'Lost connection to server: {e}') from e while data: try: data = self._sock.recv(recv_buffer)