From 3861c4438ad3d7e48f843d7dab7c97b5dce8f2ec Mon Sep 17 00:00:00 2001 From: Oleg Kalachev Date: Sat, 29 Aug 2026 16:52:34 +0300 Subject: [PATCH] Make failed mavlink commands exception more verbose in pytflix --- tools/pyflix/flix.py | 4 +++- tools/test.py | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/pyflix/flix.py b/tools/pyflix/flix.py index 8321d67..81097c0 100644 --- a/tools/pyflix/flix.py +++ b/tools/pyflix/flix.py @@ -264,7 +264,9 @@ class Flix: self.mavlink.command_long_send(self.system_id, 0, command, 0, *params) # type: ignore ack = self.wait('mavlink.COMMAND_ACK', value=lambda msg: msg.command == command, timeout=0.1) if ack.result != mavlink.MAV_RESULT_ACCEPTED: - raise RuntimeError(f'Command {command} failed with result {ack.result}') + name = getattr(mavlink.enums['MAV_CMD'].get(command, {}), 'name', f'UNKNOWN({command})') + result = getattr(mavlink.enums['MAV_RESULT'].get(ack.result, {}), 'name', f'UNKNOWN({ack.result})') + raise RuntimeError(f'Command {name} failed with result {result}') return except TimeoutError: continue diff --git a/tools/test.py b/tools/test.py index dca8046..2fdd8a8 100755 --- a/tools/test.py +++ b/tools/test.py @@ -46,5 +46,8 @@ def test(): flix.set_mode('AUTO') flix.wait('mode', 'AUTO') - raises(RuntimeError, lambda: flix._command_send(mavlink.MAV_CMD_DO_SET_MODE, [0, 99, 0, 0, 0, 0, 0])) # invalid mode - raises(RuntimeError, lambda: flix._command_send(mavlink.MAV_CMD_DO_PARACHUTE, [0, 0, 0, 0, 0, 0, 0])) # unsupported command + print("=== Check command errors") + with raises(RuntimeError, match='MAV_RESULT_DENIED'): + flix._command_send(mavlink.MAV_CMD_DO_SET_MODE, [0, 99, 0, 0, 0, 0, 0]) # invalid mode + with raises(RuntimeError, match='MAV_RESULT_UNSUPPORTED'): + flix._command_send(mavlink.MAV_CMD_DO_PARACHUTE, [0, 0, 0, 0, 0, 0, 0]) # unsupported command