From 522c99e3a2a6a368fc6a511d3e243bad54a3a6ba Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Tue, 15 Sep 2026 15:43:49 +0200 Subject: [PATCH] reduce logging of communication error messages Change-Id: I2de62c023327160ffeba2813d652ae340c7f6de0 --- frappy/io.py | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/frappy/io.py b/frappy/io.py index 6328dbc2..7c81cbf0 100644 --- a/frappy/io.py +++ b/frappy/io.py @@ -126,7 +126,8 @@ class IOBase(Communicator): _reconnectCallbacks = None _conn = None - _last_error = None # this is None only until the first connection success + _last_error = None # the last error (or a success state) + # _last_error is None only until the first connection success _lock = None _last_connect_attempt = 0 @@ -349,14 +350,15 @@ class StringIO(IOBase): self.comLog('< %s', reply) return reply except Exception as e: - new_error = 'disconnected' if self._conn is None else repr(e) + not_severe = isinstance(e, SECoPError) + if self._conn is None: + new_error = 'disconnected' + e = None + else: + new_error = repr(e) if new_error != self._last_error: - # suppress subsequent equal error messages - # this is in addition to the mechanism in Module.callPollFunc - # as the same error would appear potentially in a lot of - # methods - if isinstance(e, SECoPError): - self.log.error(new_error) + if not_severe: + self.log.error('%s -> %s', self._last_error, new_error) else: self.log.exception(new_error) raise SilentError(new_error) from e @@ -456,6 +458,12 @@ class StringIO(IOBase): self.log.error(self._last_error) raise SilentError(repr(e)) from e + @Command + def reconnect(self): + """close and open connection""" + self.closeConnection() + self.read_is_connected() + def make_regexp(string): """create a bytes regexp pattern from a string describing a bytes pattern @@ -538,14 +546,15 @@ class BytesIO(IOBase): self.comLog('< %s', hexify(reply)) return self.getFullReply(request, reply) except Exception as e: - new_error = 'disconnected' if self._conn is None else repr(e) + not_severe = isinstance(e, SECoPError) + if self._conn is None: + new_error = 'disconnected' + e = None + else: + new_error = repr(e) if new_error != self._last_error: - # suppress subsequent equal error messages - # this is in addition to the mechanism in Module.callPollFunc - # as the same error would appear potentially in a lot of - # methods - if isinstance(e, SECoPError): - self.log.error(new_error) + if not_severe: + self.log.error('%s -> %s', self._last_error, new_error) else: self.log.exception(new_error) raise SilentError(new_error) from e