improve the error messages; change from exceptions where it makes sense

This commit is contained in:
Mike Kinney
2021-12-07 14:19:54 -08:00
parent 2ee59c1e21
commit 592be9a2a1
6 changed files with 49 additions and 21 deletions

View File

@@ -7,7 +7,7 @@ import stat
import serial
from .stream_interface import StreamInterface
from .util import findPorts
from .util import findPorts, our_exit
class SerialInterface(StreamInterface):
"""Interface class for meshtastic devices over a serial link"""
@@ -23,11 +23,13 @@ class SerialInterface(StreamInterface):
if devPath is None:
ports = findPorts()
logging.debug(f"ports:{ports}")
if len(ports) == 0:
raise Exception("No Meshtastic devices detected")
our_exit("Warning: No Meshtastic devices detected.")
elif len(ports) > 1:
raise Exception(
f"Multiple ports detected, you must specify a device, such as {ports[0]}")
message = "Warning: Multiple serial ports were detected so one serial port must be specified with the '--port'.\n"
message += f" Ports detected:{ports}"
our_exit(message)
else:
devPath = ports[0]