Fix UART bridge UnboundLocalError: lines variable scope in saltybot_cmd_node #683

Closed
opened 2026-03-17 22:35:26 -04:00 by seb · 0 comments
Owner

Bug

saltybot_cmd_node.py crashes with UnboundLocalError: local variable "lines" referenced before assignment in _read_cb().

Root cause

lines = [] is initialized inside the with self._ser_lock block, but only when self._ser is not None and is open. If the serial port is closed/None, lines is never assigned, causing the crash on for raw in lines: outside the lock.

Fix

Move lines = [] initialization to the top of _read_cb(), before the with self._ser_lock: block.

def _read_cb(self):
    lines = []  # <-- move here
    with self._ser_lock:
        ...

File

jetson/ros2_ws/src/saltybot_bridge/saltybot_bridge/saltybot_cmd_node.py

## Bug `saltybot_cmd_node.py` crashes with `UnboundLocalError: local variable "lines" referenced before assignment` in `_read_cb()`. ## Root cause `lines = []` is initialized inside the `with self._ser_lock` block, but only when `self._ser` is not None and is open. If the serial port is closed/None, `lines` is never assigned, causing the crash on `for raw in lines:` outside the lock. ## Fix Move `lines = []` initialization to the top of `_read_cb()`, before the `with self._ser_lock:` block. ```python def _read_cb(self): lines = [] # <-- move here with self._ser_lock: ... ``` ## File `jetson/ros2_ws/src/saltybot_bridge/saltybot_bridge/saltybot_cmd_node.py`
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: seb/saltylab-firmware#683
No description provided.