From 906f787748ab819f247b0c3e98a9352450fd43a4 Mon Sep 17 00:00:00 2001 From: Jeremy Shen Date: Thu, 11 Jun 2026 18:23:40 +0800 Subject: [PATCH] fix: guard UART window creation with try-except to prevent silent crash On Windows the UartMonitorWindow could crash instantly without any error message. Added try-except around window creation in _read_serial so errors are logged instead of silently killing the window. Also added empty port guard before attempting to open. --- src/gui/main_window.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/gui/main_window.py b/src/gui/main_window.py index be6bc26..87890dc 100644 --- a/src/gui/main_window.py +++ b/src/gui/main_window.py @@ -1585,12 +1585,20 @@ class MainWindow(ctk.CTk): def _read_serial(self) -> None: """Open the UART Monitor window.""" - port = self._port_var.get() + port = self._port_var.get().strip() + if not port: + self._log_message(" ✗ No serial port selected") + return baudrate = self._config.serial_baudrate if self._config else 115200 - self._uart_window = UartMonitorWindow( - self, port=port, baudrate=baudrate, - on_log=self._log_message, - ) + try: + self._uart_window = UartMonitorWindow( + self, port=port, baudrate=baudrate, + on_log=self._log_message, + ) + except Exception as e: + self._log_message(f" ✗ Failed to open UART window: {e}") + import traceback + self._log_message(traceback.format_exc()) def _test_serial_version(self) -> None: """Test serial port by sending 'ver()' command and parsing response."""