From 45548e0a3e218e09c44423bf2b9460700d55cfe9 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Mon, 28 Mar 2022 04:44:14 +0300 Subject: [PATCH] TransportModem: raise TransportIOError exception on I/O error --- transport.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/transport.py b/transport.py index 5ee0072..90ad710 100644 --- a/transport.py +++ b/transport.py @@ -23,6 +23,10 @@ import serial import abc +class TransportIOError(Exception): + ''' I/O error during read/write operation ''' + + class Transport(abc.ABC): ''' Abstract transport layer for DebugMux ''' @@ -70,11 +74,17 @@ class TransportModem(Transport): def write(self, data: bytes) -> int: ''' Write the given data bytes ''' - return self._sl.write(data) + try: + return self._sl.write(data) + except Exception as e: + raise TransportIOError('Failed to write() data') from e def read(self, length: int = 0) -> bytes: ''' Read the given number of bytes ''' - return self._sl.read(length) + try: + return self._sl.read(length) + except Exception as e: + raise TransportIOError('Failed to read() data') from e def send_at_cmd(self, cmd: str, handle_echo: bool = True) -> None: ''' Send an AT command to the modem '''