From e2d344cf1e336e844a4a3b0c87243c2dbbb847fe Mon Sep 17 00:00:00 2001 From: eduardo Date: Thu, 20 Jun 2024 08:01:06 +0200 Subject: [PATCH] Add error handling and print traceback in RFID tests The update introduces IOError specific exception handling in the RFID tests. It also prints a traceback for both IOError and general exceptions. This is done to better diagnose issues related to connectivity and IO in the tests as and when they occur. The code is also cleaned for better readability by fixing indentation and removing unnecessary comments and spaces. --- src/test/rfid.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/test/rfid.py b/src/test/rfid.py index 322f2c9..14caac2 100644 --- a/src/test/rfid.py +++ b/src/test/rfid.py @@ -2,6 +2,7 @@ import logging import platform import sys import time +import traceback from datetime import datetime from pathlib import Path @@ -10,7 +11,6 @@ import ndef import nfc from nfc.clf import RemoteTarget - logging.basicConfig( format="{asctime}:{name}:{levelname}:{message}", datefmt="%Y-%m-%dT%H-%M-%S%z", @@ -31,11 +31,11 @@ logging.basicConfig( **({"errors": "surrogateescape"} if sys.version_info.major >= 3 and sys.version_info.minor >= 10 else {}), ) -connected=False +connected = False is_win = platform.system().lower() == "windows" if is_win: - dev_list=['com:COM5:pn532'] + dev_list = ['com:COM5:pn532'] else: dev_list = ['tty:USB0:pn532', 'tty:USB1:pn532', 'tty:USB2:pn532'] while True: @@ -80,10 +80,15 @@ while True: print("NO TARGET") else: print("NOT CONNECTED") + except IOError as io_err: + print(f"IOError: {io_err}") + traceback.print_exc() + connected = False except Exception as e: - print(f"EXCEPTION {e}") - connected=False + print(f"General Exception: {e}") + traceback.print_exc() + connected = False time.sleep(1) print("EXITING") -clf.close() \ No newline at end of file +clf.close()