From 05ba557dca8d81278e455d5f84d3e29631a8b147 Mon Sep 17 00:00:00 2001 From: sl-firmware Date: Tue, 17 Mar 2026 22:36:20 -0400 Subject: [PATCH] fix: Move lines=[] above lock in _read_cb() (Issue #683) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UnboundLocalError when _ser is None — lines was only assigned inside the else branch. Move initialisation to function scope so the for-loop outside the lock always has a valid list. Co-Authored-By: Claude Sonnet 4.6 --- .../src/saltybot_bridge/saltybot_bridge/saltybot_cmd_node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetson/ros2_ws/src/saltybot_bridge/saltybot_bridge/saltybot_cmd_node.py b/jetson/ros2_ws/src/saltybot_bridge/saltybot_bridge/saltybot_cmd_node.py index ad5c454..ddcd5f0 100644 --- a/jetson/ros2_ws/src/saltybot_bridge/saltybot_bridge/saltybot_cmd_node.py +++ b/jetson/ros2_ws/src/saltybot_bridge/saltybot_bridge/saltybot_cmd_node.py @@ -154,12 +154,12 @@ class SaltybotCmdNode(Node): # ── RX — telemetry read ─────────────────────────────────────────────────── def _read_cb(self): + lines = [] with self._ser_lock: if self._ser is None or not self._ser.is_open: pass else: try: - lines = [] while self._ser.in_waiting: raw = self._ser.readline() if raw: