diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 051a7a8..9fa2a4a 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -1383,6 +1383,11 @@ def common(): if not stripped_ham_name: meshtastic.util.our_exit("ERROR: Ham radio callsign cannot be empty or contain only whitespace characters") + # Early validation for OTA firmware file before attempting device connection + if hasattr(args, 'ota_update') and args.ota_update is not None: + if not os.path.isfile(args.ota_update): + meshtastic.util.our_exit(f"Error: OTA firmware file not found: {args.ota_update}", 1) + if have_powermon: create_power_meter() diff --git a/meshtastic/tests/test_main.py b/meshtastic/tests/test_main.py index 772717c..90dc857 100644 --- a/meshtastic/tests/test_main.py +++ b/meshtastic/tests/test_main.py @@ -3157,6 +3157,9 @@ def test_main_ota_update_file_not_found(capsys): assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == 1 + out, err = capsys.readouterr() + assert "OTA firmware file not found" in out + assert "/nonexistent/firmware.bin" in out @pytest.mark.unit