From dc6e8e51d7bb8668927a97e8bf624293f778f787 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Mon, 29 Aug 2022 16:37:28 +0200 Subject: [PATCH] dist/tools/usb-serial/ttys.py: improve error handling Do not throw an exception when called with `--most-recent` but no matching serial was found. --- dist/tools/usb-serial/ttys.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/dist/tools/usb-serial/ttys.py b/dist/tools/usb-serial/ttys.py index 36cc36f214..1a98ddd0cb 100755 --- a/dist/tools/usb-serial/ttys.py +++ b/dist/tools/usb-serial/ttys.py @@ -213,11 +213,14 @@ def print_ttys(args): ttys.append(tty) if args.most_recent: - most_recent = ttys[0] - for tty in ttys: - if tty["ctime"] > most_recent["ctime"]: - most_recent = tty - ttys = [most_recent] + if len(ttys) > 0: + most_recent = ttys[0] + for tty in ttys: + if tty["ctime"] > most_recent["ctime"]: + most_recent = tty + ttys = [most_recent] + else: + ttys = [] print_results(args, ttys)