diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index cf64205..e6f0a5b 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -47,6 +47,12 @@ class MeshInterface: debugOut """ + class MeshInterfaceError(Exception): + """An exception class for general mesh interface errors""" + def __init__(self, message): + self.message = message + super().__init__(self.message) + def __init__(self, debugOut=None, noProto=False): """Constructor @@ -313,7 +319,7 @@ class MeshInterface: f"mesh_pb2.Constants.DATA_PAYLOAD_LEN: {mesh_pb2.Constants.DATA_PAYLOAD_LEN}" ) if len(data) > mesh_pb2.Constants.DATA_PAYLOAD_LEN: - raise Exception("Data payload too big") + raise MeshInterface.MeshInterfaceError("Data payload too big") if ( portNum == portnums_pb2.PortNum.UNKNOWN_APP @@ -542,25 +548,25 @@ class MeshInterface: and self.localNode.waitForConfig() ) if not success: - raise Exception("Timed out waiting for interface config") + raise MeshInterface.MeshInterfaceError("Timed out waiting for interface config") def waitForAckNak(self): """Wait for the ack/nak""" success = self._timeout.waitForAckNak(self._acknowledgment) if not success: - raise Exception("Timed out waiting for an acknowledgment") + raise MeshInterface.MeshInterfaceError("Timed out waiting for an acknowledgment") def waitForTraceRoute(self, waitFactor): """Wait for trace route""" success = self._timeout.waitForTraceRoute(waitFactor, self._acknowledgment) if not success: - raise Exception("Timed out waiting for traceroute") + raise MeshInterface.MeshInterfaceError("Timed out waiting for traceroute") def waitForTelemetry(self): """Wait for telemetry""" success = self._timeout.waitForTelemetry(self._acknowledgment) if not success: - raise Exception("Timed out waiting for telemetry") + raise MeshInterface.MeshInterfaceError("Timed out waiting for telemetry") def getMyNodeInfo(self): """Get info about my node.""" @@ -595,7 +601,7 @@ class MeshInterface: and raise an exception""" if not self.noProto: if not self.isConnected.wait(timeout): # timeout after x seconds - raise Exception("Timed out waiting for connection completion") + raise MeshInterface.MeshInterfaceError("Timed out waiting for connection completion") # If we failed while connecting, raise the connection to the client if self.failure: @@ -604,7 +610,7 @@ class MeshInterface: def _generatePacketId(self): """Get a new unique packet ID""" if self.currentPacketId is None: - raise Exception("Not connected yet, can not generate packet") + raise MeshInterface.MeshInterfaceError("Not connected yet, can not generate packet") else: self.currentPacketId = (self.currentPacketId + 1) & 0xFFFFFFFF return self.currentPacketId @@ -773,7 +779,7 @@ class MeshInterface: failmsg = None if failmsg: - self.failure = Exception(failmsg) + self.failure = MeshInterface.MeshInterfaceError(failmsg) self.isConnected.set() # let waitConnected return this exception self.close() @@ -919,7 +925,7 @@ class MeshInterface: def _getOrCreateByNum(self, nodeNum): """Given a nodenum find the NodeInfo in the DB (or create if necessary)""" if nodeNum == BROADCAST_NUM: - raise Exception("Can not create/find nodenum by the broadcast num") + raise MeshInterface.MeshInterfaceError("Can not create/find nodenum by the broadcast num") if nodeNum in self.nodesByNum: return self.nodesByNum[nodeNum]