From bc1aa19b2879d342c23b39da643a7e956bf4c262 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 18 Mar 2026 22:54:10 +1100 Subject: [PATCH] Tools: avoid errors for catching bare exception --- Tools/ardupilotwaf/linux.py | 2 +- Tools/ardupilotwaf/sitl.py | 2 +- Tools/autotest/arducopter.py | 24 ++++++------- Tools/autotest/arduplane.py | 2 +- Tools/autotest/autotest.py | 10 +++--- Tools/autotest/balancebot.py | 2 +- Tools/autotest/bisect-helper.py | 2 +- Tools/autotest/examples.py | 2 +- Tools/autotest/pysim/util.py | 6 ++-- Tools/autotest/rover.py | 8 ++--- Tools/autotest/sim_vehicle.py | 10 +++--- Tools/autotest/test_param_upgrade.py | 2 +- Tools/autotest/vehicle_test_suite.py | 48 ++++++++++++------------- Tools/scripts/annotate_params.py | 2 +- Tools/scripts/bin2hex.py | 2 +- Tools/scripts/build_binaries.py | 6 ++-- Tools/scripts/build_script_base.py | 2 +- Tools/scripts/check_firmware_version.py | 2 +- Tools/scripts/generate_manifest.py | 10 +++--- Tools/scripts/size_history.py | 2 +- Tools/scripts/tfminiplus.py | 2 +- Tools/scripts/uploader.py | 20 +++++------ 22 files changed, 84 insertions(+), 84 deletions(-) diff --git a/Tools/ardupilotwaf/linux.py b/Tools/ardupilotwaf/linux.py index 6c7f73127a4..eb8c960557a 100644 --- a/Tools/ardupilotwaf/linux.py +++ b/Tools/ardupilotwaf/linux.py @@ -47,7 +47,7 @@ def configure(cfg): try: hwdef_obj = generate_hwdef_h(env) - except Exception: + except Exception: # noqa: BLE001 traceback.print_exc() cfg.fatal("Failed to process hwdef.dat") hal_common.process_hwdef_results(cfg, hwdef_obj) diff --git a/Tools/ardupilotwaf/sitl.py b/Tools/ardupilotwaf/sitl.py index 43dd1640b96..2e840246a69 100644 --- a/Tools/ardupilotwaf/sitl.py +++ b/Tools/ardupilotwaf/sitl.py @@ -47,7 +47,7 @@ def configure(cfg): try: hwdef_obj = generate_hwdef_h(env) - except Exception: + except Exception: # noqa: BLE001 traceback.print_exc() cfg.fatal("Failed to process hwdef.dat") hal_common.process_hwdef_results(cfg, hwdef_obj) diff --git a/Tools/autotest/arducopter.py b/Tools/autotest/arducopter.py index 8a225d793ed..cdaa32a4df4 100644 --- a/Tools/autotest/arducopter.py +++ b/Tools/autotest/arducopter.py @@ -3265,7 +3265,7 @@ class AutoTestCopter(vehicle_test_suite.TestSuite): if ((flow_scalar_y > 30) or (flow_scalar_y < -30)): raise NotAchievedException("FlowCal failed to set FLOW_FYSCALER correctly") - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e @@ -4929,7 +4929,7 @@ class AutoTestCopter(vehicle_test_suite.TestSuite): self.set_rc(2, 1500) self.do_RTL() - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) self.disarm_vehicle(force=True) ex = e @@ -5161,7 +5161,7 @@ class AutoTestCopter(vehicle_test_suite.TestSuite): if not self.current_onboard_log_contains_message("PL"): raise NotAchievedException("Did not see expected PL message") - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e self.reboot_sitl() @@ -9103,7 +9103,7 @@ class AutoTestCopter(vehicle_test_suite.TestSuite): self.set_rc(2, 1500) self.do_RTL() - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e self.context_pop() @@ -10366,7 +10366,7 @@ class AutoTestCopter(vehicle_test_suite.TestSuite): ) try: self.arm_vehicle() - except Exception: + except Exception: # noqa: BLE001 pass self.delay_sim_time(1) # servo function maps only periodically updated # self.send_debug_trap() @@ -10394,7 +10394,7 @@ class AutoTestCopter(vehicle_test_suite.TestSuite): self.delay_sim_time(0.1) try: self.wait_text("LandingGear: RETRACT", check_context=True, timeout=0.1) - except Exception: + except Exception: # noqa: BLE001 continue self.progress("Retracted") break @@ -10415,13 +10415,13 @@ class AutoTestCopter(vehicle_test_suite.TestSuite): ) try: self.wait_text("LandingGear: DEPLOY", check_context=True, timeout=0.1) - except Exception: + except Exception: # noqa: BLE001 continue self.progress("Deployed") break self.disarm_vehicle() - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e self.context_pop() @@ -10596,7 +10596,7 @@ class AutoTestCopter(vehicle_test_suite.TestSuite): (expected_dist, rf.min_distance)) self.context_pop() - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e @@ -11733,7 +11733,7 @@ class AutoTestCopter(vehicle_test_suite.TestSuite): self.assert_message_rate_hz("ATTITUDE", 20) self.assert_message_rate_hz("SCALED_PRESSURE", 5) - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e @@ -12548,7 +12548,7 @@ class AutoTestCopter(vehicle_test_suite.TestSuite): self.wait_extended_sys_state(vtol_state=mavutil.mavlink.MAV_VTOL_STATE_MC, landed_state=mavutil.mavlink.MAV_LANDED_STATE_IN_AIR, timeout=60) self.land_and_disarm() - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e self.set_message_rate_hz(mavutil.mavlink.MAVLINK_MSG_ID_EXTENDED_SYS_STATE, -1) @@ -15496,7 +15496,7 @@ RTL_ALT_M 111 self.assert_receive_message('HEARTBEAT', mav=mav3, verbose=2) self.drain_mav() - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e finally: diff --git a/Tools/autotest/arduplane.py b/Tools/autotest/arduplane.py index e2bca578a77..c3f06b49266 100644 --- a/Tools/autotest/arduplane.py +++ b/Tools/autotest/arduplane.py @@ -4594,7 +4594,7 @@ class AutoTestPlane(vehicle_test_suite.TestSuite): raise NotAchievedException( "New home not where it should be (dist=%f) (want=%s) (got=%s)" % (delta, str(new_home), str(post_reboot_home))) - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e diff --git a/Tools/autotest/autotest.py b/Tools/autotest/autotest.py index 5ffec798748..f36dff3f7c7 100755 --- a/Tools/autotest/autotest.py +++ b/Tools/autotest/autotest.py @@ -99,7 +99,7 @@ def build_examples(**kwargs): print("Running build.examples for %s" % target) try: util.build_examples(target, **kwargs) - except Exception as e: + except Exception as e: # noqa: BLE001 print("Failed build_examples on board=%s" % target) print(str(e)) return False @@ -113,7 +113,7 @@ def build_unit_tests(**kwargs): print("Running build.unit_tests for %s" % target) try: util.build_tests(target, **kwargs) - except Exception as e: + except Exception as e: # noqa: BLE001 print("Failed build.unit_tests on board=%s" % target) print(str(e)) return False @@ -249,7 +249,7 @@ def alarm_handler(signum, frame): convert_gpx() write_fullresults() os.killpg(0, signal.SIGKILL) - except Exception: + except Exception: # noqa: BLE001 pass sys.exit(1) @@ -297,7 +297,7 @@ def binary_path(step, debug=False): """Get vehicle binary path.""" try: vehicle = step.split(".")[1] - except Exception: + except IndexError: return None if vehicle not in __bin_names: @@ -751,7 +751,7 @@ def run_tests(steps): failed_testinstances[step].append(testinstance) results.add(step, 'FAILED', time.time() - t1) - except Exception as msg: + except Exception as msg: # noqa: BLE001 passed = False failed.append(step) print(">>>> FAILED STEP: %s at %s (%s)" % diff --git a/Tools/autotest/balancebot.py b/Tools/autotest/balancebot.py index c5088e4c7b9..c387411855f 100644 --- a/Tools/autotest/balancebot.py +++ b/Tools/autotest/balancebot.py @@ -85,7 +85,7 @@ class AutoTestBalanceBot(AutoTestRover): if delta > 5: raise NotAchievedException("wheel distance incorrect") self.disarm_vehicle() - except Exception as e: + except Exception as e: # noqa: BLE001 self.progress("Caught exception: %s" % self.get_exception_stacktrace(e)) self.disarm_vehicle() diff --git a/Tools/autotest/bisect-helper.py b/Tools/autotest/bisect-helper.py index a64cb4459c4..54d02478f70 100755 --- a/Tools/autotest/bisect-helper.py +++ b/Tools/autotest/bisect-helper.py @@ -375,7 +375,7 @@ if __name__ == '__main__': try: bisecter.run() -except Exception as e: +except Exception as e: # noqa: BLE001 print("Caught exception in bisect-helper: %s" % str(e)) print(get_exception_stacktrace(e)) sys.exit(129) # should abort the bisect process diff --git a/Tools/autotest/examples.py b/Tools/autotest/examples.py index 70dd4883c69..716d9b05d31 100644 --- a/Tools/autotest/examples.py +++ b/Tools/autotest/examples.py @@ -131,7 +131,7 @@ def run_examples(debug=False, valgrind=False, gdb=False): continue try: run_example(afile, filepath, valgrind=valgrind, gdb=gdb) - except Exception as e: + except Exception as e: # noqa: BLE001 print("Example failed with exception") print_exception_stacktrace(e) failures.append(afile) diff --git a/Tools/autotest/pysim/util.py b/Tools/autotest/pysim/util.py index d2ecf310f01..a54074312e9 100644 --- a/Tools/autotest/pysim/util.py +++ b/Tools/autotest/pysim/util.py @@ -315,11 +315,11 @@ def pexpect_close(p): time.sleep(0.05) try: p.close() - except Exception: + except Exception: # noqa: BLE001 pass try: p.close(force=True) - except Exception: + except Exception: # noqa: BLE001 pass if p in close_list: close_list.remove(p) @@ -335,7 +335,7 @@ def pexpect_drain(p): """Drain any pending input.""" try: p.read_nonblocking(1000, timeout=0) - except Exception: + except Exception: # noqa: BLE001 pass diff --git a/Tools/autotest/rover.py b/Tools/autotest/rover.py index 5aec5ba309d..8555d6c1c75 100644 --- a/Tools/autotest/rover.py +++ b/Tools/autotest/rover.py @@ -727,7 +727,7 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm) mavproxy.send('switch %u\n' % num) self.wait_mode(expected) self.stop_mavproxy(mavproxy) - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e @@ -1315,13 +1315,13 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm) self.mav.mav.srcSystem = 1 self.arm_vehicle(timeout=5) self.disarm_vehicle() - except Exception as e: + except Exception as e: # noqa: BLE001 comp_arm_exception = e self.mav.mav.srcSystem = old_srcSystem if comp_arm_exception is not None: raise comp_arm_exception - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e self.mav.mav.srcSystem = old_srcSystem @@ -4968,7 +4968,7 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm) self.wait_location(target, timeout=300) self.do_RTL() self.disarm_vehicle() - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e self.context_pop() diff --git a/Tools/autotest/sim_vehicle.py b/Tools/autotest/sim_vehicle.py index 844cd8f13d4..07585492f87 100755 --- a/Tools/autotest/sim_vehicle.py +++ b/Tools/autotest/sim_vehicle.py @@ -173,7 +173,7 @@ def cygwin_pidof(proc_name): if cmd == proc_name: try: pid = int(line_split[0].strip()) - except Exception: + except ValueError: pid = int(line_split[1].strip()) if pid not in pids: pids.append(pid) @@ -315,7 +315,7 @@ def kill_tasks(): kill_tasks_psutil(victim_names) except ImportError: kill_tasks_pkill(victim_names) - except Exception as e: + except Exception as e: # noqa: BLE001 progress("kill_tasks failed: {}".format(str(e))) @@ -516,7 +516,7 @@ def find_geocoder_location(locname): # Step 1: Attempt the lookup try: j = geocoder.osm(locname) - except Exception as e: + except Exception as e: # noqa: BLE001 # Handle network/blocked errors (like 403) err_msg = str(e) if '403' in err_msg: @@ -604,7 +604,7 @@ def run_cmd_blocking(what, cmd, quiet=False, check=False, **kw): try: p = subprocess.Popen(cmd, **kw) ret = os.waitpid(p.pid, 0) - except Exception as e: + except Exception as e: # noqa: BLE001 print("[%s] An exception has occurred with command: '%s'" % (what, (' ').join(cmd))) print(e) sys.exit(1) @@ -852,7 +852,7 @@ def start_vehicle(binary, opts, stuff, spawns=None): # Parse start_time into a double precision number specifying seconds since 1900. try: start_time_UTC = time.mktime(datetime.datetime.strptime(cmd_opts.start_time, '%Y-%m-%d-%H:%M').timetuple()) - except Exception: + except ValueError: print("Incorrect start time format - require YYYY-MM-DD-HH:MM (given %s)" % cmd_opts.start_time) sys.exit(1) diff --git a/Tools/autotest/test_param_upgrade.py b/Tools/autotest/test_param_upgrade.py index 15f5d24a333..13f4479a318 100755 --- a/Tools/autotest/test_param_upgrade.py +++ b/Tools/autotest/test_param_upgrade.py @@ -195,7 +195,7 @@ class TestParamUpgradeForVehicle(): path = pathlib.Path(self.tmpdir, f"process-failure-{int(time.time())}") path.write_text(output) self.progress("Wrote process failure file (%s)" % path) - except Exception: + except Exception: # noqa: BLE001 self.progress("Writing process failure file failed") raise subprocess.CalledProcessError( returncode, cmd_list) diff --git a/Tools/autotest/vehicle_test_suite.py b/Tools/autotest/vehicle_test_suite.py index e536c16e7ab..b4efa388243 100644 --- a/Tools/autotest/vehicle_test_suite.py +++ b/Tools/autotest/vehicle_test_suite.py @@ -294,7 +294,7 @@ class Telem(object): if self.port is not None: try: self.port.close() # might be reopening - except Exception: + except Exception: # noqa: BLE001 pass self.port = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.port.connect(self.destination_address) @@ -2490,7 +2490,7 @@ class TestSuite(abc.ABC): pass except socket.error: pass - except Exception as e: + except Exception as e: # noqa: BLE001 self.progress("Got unexpected exception (%s)" % str(type(e))) pass @@ -3201,7 +3201,7 @@ class TestSuite(abc.ABC): self.stop_SITL() try: del self.valgrind_restart_customisations - except Exception: + except AttributeError: pass self.start_SITL(wipe=True) self.set_streamrate(self.sitl_streamrate()) @@ -3763,7 +3763,7 @@ class TestSuite(abc.ABC): self.run_cmd_enable_high_latency(False) self.assert_message_rate_hz("HIGH_LATENCY2", 5, mav=self.mav) - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e @@ -8551,7 +8551,7 @@ class TestSuite(abc.ABC): self.progress("Prearm bit never went true. Attempting arm to elicit reason from autopilot") try: self.arm_vehicle() - except Exception: + except Exception: # noqa: BLE001 pass raise AutoTestTimeoutException("Prearm bit never went true") if self.sensor_has_state(mavutil.mavlink.MAV_SYS_STATUS_PREARM_CHECK, True, True, True): @@ -9147,7 +9147,7 @@ Also, ignores heartbeats not from our target system''' self.set_parameter("SIM_SPEEDUP", test.speedup) test_function(**test_kwargs) - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e # reset the message hooks; we've failed-via-exception and @@ -9173,7 +9173,7 @@ Also, ignores heartbeats not from our target system''' try: self.wait_heartbeat() ardupilot_alive = True - except Exception: + except Exception: # noqa: BLE001 # process is dead self.progress("No heartbeat after test", send_statustext=False) self.dump_process_status(result) @@ -9183,7 +9183,7 @@ Also, ignores heartbeats not from our target system''' try: self.context_pop(process_interaction_allowed=ardupilot_alive, hooks_already_removed=hooks_removed) - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e, send_statustext=False) passed = False @@ -9239,7 +9239,7 @@ Also, ignores heartbeats not from our target system''' while len(self.contexts) > old_contexts_length: try: self.context_pop(process_interaction_allowed=ardupilot_alive, hooks_already_removed=hooks_removed) - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e, send_statustext=False) self.progress("Done popping extra contexts") @@ -10219,7 +10219,7 @@ Also, ignores heartbeats not from our target system''' do_prep_mag_cal_test(mavproxy, curr_params) do_test_mag_cal(mavproxy, curr_params, ntest_compass) - except Exception as e: + except Exception as e: # noqa: BLE001 self.progress("Caught exception: %s" % self.get_exception_stacktrace(e)) ex = e @@ -10580,7 +10580,7 @@ Also, ignores heartbeats not from our target system''' self.reboot_sitl() self.wait_ready_to_arm(timeout=60) - except Exception as e: + except Exception as e: # noqa: BLE001 ex = e self.context_pop() @@ -10626,7 +10626,7 @@ Also, ignores heartbeats not from our target system''' raise NotAchievedException("Exceptionally low transfer rate (%u < %u)" % (rate, desired_rate)) self.disarm_vehicle() mavproxy.send('repeat remove 0\n') - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) self.disarm_vehicle() ex = e @@ -10710,7 +10710,7 @@ Also, ignores heartbeats not from our target system''' mavproxy.send("log erase\n") mavproxy.expect("Chip erase complete") - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e mavproxy.send("module unload log\n") @@ -10741,7 +10741,7 @@ Also, ignores heartbeats not from our target system''' m = mlog.recv_match() if m is None: break - except Exception as e: + except Exception as e: # noqa: BLE001 raise NotAchievedException("Error reading log file %s: %s" % (logname, str(e))) herrors = 0 @@ -10821,7 +10821,7 @@ Also, ignores heartbeats not from our target system''' mavproxy.send("log erase\n") mavproxy.expect("Chip erase complete") - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e @@ -11309,7 +11309,7 @@ Also, ignores heartbeats not from our target system''' self.set_message_rate_hz(message, rate) for message in messages: self.assert_message_rate_hz(message, rate) - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e @@ -11376,7 +11376,7 @@ Also, ignores heartbeats not from our target system''' if m.result != mavutil.mavlink.MAV_RESULT_FAILED: raise NotAchievedException("Getting rate of unsupported message is a failure") - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e @@ -11530,7 +11530,7 @@ Also, ignores heartbeats not from our target system''' self.wait_statustext("Config error", wallclock_timeout=True) self.progress("Setting %s to %f" % (parameter_name, new_parameter_value)) self.set_parameter(parameter_name, new_parameter_value) - except Exception as e: + except Exception as e: # noqa: BLE001 ex = e self.progress("Resetting SIM_BARO_COUNT") @@ -12925,7 +12925,7 @@ switch value''' self.context_pop() self.set_parameter("AFS_TERMINATE", 0) - except Exception as e: + except Exception as e: # noqa: BLE001 ex = e try: self.do_fence_disable() @@ -13084,7 +13084,7 @@ switch value''' (v, pname, expected_v, error_pct)) else: self.progress("Correct value %.4f for %s error %.2f%%" % (v, pname, error_pct)) - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e self.mavproxy_unload_module(mavproxy, "relay") @@ -14459,7 +14459,7 @@ switch value''' self.progress("Writing vtx_unknown") crsf.write_data_id(crsf.dataid_vtx_unknown) self.delay_sim_time(5) - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e self.context_pop() @@ -14731,12 +14731,12 @@ switch value''' try: mavproxy.expect("No transfer in progress", timeout=1) break - except Exception: + except Exception: # noqa: BLE001 continue # terminate the connection, or it may still be in progress the next time an FTP is attempted: mavproxy.send("ftp cancel\n") mavproxy.expect("Terminated session") - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e @@ -14764,7 +14764,7 @@ switch value''' raise NotAchievedException("No directories?!") expected_line = " D %s" % some_directory mavproxy.expect(expected_line) # one line from the ftp list output - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) ex = e diff --git a/Tools/scripts/annotate_params.py b/Tools/scripts/annotate_params.py index 8287cfac3f9..1f631b5babf 100755 --- a/Tools/scripts/annotate_params.py +++ b/Tools/scripts/annotate_params.py @@ -405,7 +405,7 @@ def main(): update_parameter_documentation(doc_dict, args.target, args.sort) if args.verbose: print_read_only_params(doc_dict) - except Exception as exp: # pylint: disable=W0718 + except Exception as exp: # pylint: disable=W0718 # noqa: BLE001 logging.fatal(exp) exit(1) # pylint: disable=R1722 diff --git a/Tools/scripts/bin2hex.py b/Tools/scripts/bin2hex.py index e8f0b2d2939..ae7a7d8b25d 100755 --- a/Tools/scripts/bin2hex.py +++ b/Tools/scripts/bin2hex.py @@ -82,7 +82,7 @@ Options: base = 16 try: offset = int(a, base) - except: + except ValueError: raise getopt.GetoptError('Bad offset value') if not args: diff --git a/Tools/scripts/build_binaries.py b/Tools/scripts/build_binaries.py index f31fe2eb233..e325cb0b650 100755 --- a/Tools/scripts/build_binaries.py +++ b/Tools/scripts/build_binaries.py @@ -503,7 +503,7 @@ is bob we will attempt to checkout bob-AVR''' if os.path.exists(ef_path): try: features_text = self.run_program("EF", [ef_path, bare_path], show_output=False) - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) self.progress("Failed to extract features") pass @@ -549,7 +549,7 @@ is bob we will attempt to checkout bob-AVR''' self.progress("Writing (%s)" % features_filepath) self.write_string_to_filepath(features_text, features_filepath) shutil.copy(path, os.path.join(tdir, target_filename)) - except Exception as e: + except Exception as e: # noqa: BLE001 self.print_exception_caught(e) self.progress("Failed to copy %s to %s: %s" % (path, tdir, str(e))) # why is touching this important? -pb20170816 @@ -575,7 +575,7 @@ is bob we will attempt to checkout bob-AVR''' def get_exception_stacktrace(self, e): try: return self._get_exception_stacktrace(e) - except Exception: + except Exception: # noqa: BLE001 — defensive wrapper, must not raise return "FAILED TO GET EXCEPTION STACKTRACE" def print_exception_caught(self, e, send_statustext=True): diff --git a/Tools/scripts/build_script_base.py b/Tools/scripts/build_script_base.py index 9006e0cb30d..da21d01b376 100644 --- a/Tools/scripts/build_script_base.py +++ b/Tools/scripts/build_script_base.py @@ -88,7 +88,7 @@ class BuildScriptBase: path = pathlib.Path(self.tmpdir, f"process-failure-{int(time.time())}") path.write_text(process_failure_content) self.progress("Wrote process failure file (%s)" % path) - except Exception: + except Exception: # noqa: BLE001 — best-effort debug-file write self.progress("Writing process failure file failed") raise subprocess.CalledProcessError( returncode, cmd_list) diff --git a/Tools/scripts/check_firmware_version.py b/Tools/scripts/check_firmware_version.py index 0033dd7fd9b..3be4120211b 100755 --- a/Tools/scripts/check_firmware_version.py +++ b/Tools/scripts/check_firmware_version.py @@ -31,7 +31,7 @@ def check_fw_version(version): try: (version_numbers, release_type) = version.split("-") (_, _, _) = version_numbers.split(".") - except Exception: + except ValueError: return False return True diff --git a/Tools/scripts/generate_manifest.py b/Tools/scripts/generate_manifest.py index 844ba2929e1..8737ddccb05 100755 --- a/Tools/scripts/generate_manifest.py +++ b/Tools/scripts/generate_manifest.py @@ -349,7 +349,7 @@ class ManifestGenerator(): return try: dlist = os.listdir(dir) - except Exception: + except OSError: print("Error listing '%s'" % dir) return for platformdir in dlist: @@ -364,12 +364,12 @@ class ManifestGenerator(): continue try: git_sha = self.git_sha_from_git_version(git_version_txt) - except Exception as ex: + except Exception as ex: # noqa: BLE001 print("Failed to parse %s" % git_version_txt, ex, file=sys.stderr) continue try: fwversion_str = self.fwversion_from_git_version(git_version_txt) - except Exception as ex: + except Exception as ex: # noqa: BLE001 print("Failed to parse APMVERSION %s" % git_version_txt, ex, file=sys.stderr) continue @@ -388,7 +388,7 @@ class ManifestGenerator(): except ValueError: print("malformed firmware-version.txt at (%s)" % (firmware_version_file,), file=sys.stderr) continue - except Exception: + except OSError: print("bad file %s" % firmware_version_file, file=sys.stderr) # this exception is swallowed.... the current archive # is incomplete. @@ -551,7 +551,7 @@ class ManifestGenerator(): try: (major, minor, patch, release_type) = self.parse_fw_version( firmware["firmware-version"]) - except Exception: + except ValueError: print("Badly formed firmware-version.txt %s" % firmware["firmware-version"], file=sys.stderr) continue some_json["mav-firmware-version"] = ".".join([major, diff --git a/Tools/scripts/size_history.py b/Tools/scripts/size_history.py index c0fc6edebc7..97fa28d266e 100755 --- a/Tools/scripts/size_history.py +++ b/Tools/scripts/size_history.py @@ -104,7 +104,7 @@ class SizeHistory(BuildScriptBase): from extract_features import ExtractFeatures ef = ExtractFeatures(elf_path) (features_in, features_not_in) = ef.extract() - except Exception as ex: + except Exception as ex: # noqa: BLE001 self.progress("Feature extraction failed: %s" % str(ex)) features_in = set() diff --git a/Tools/scripts/tfminiplus.py b/Tools/scripts/tfminiplus.py index f13ac161bee..285186f535f 100755 --- a/Tools/scripts/tfminiplus.py +++ b/Tools/scripts/tfminiplus.py @@ -13,7 +13,7 @@ import time try: import argcomplete -except: +except ImportError: pass SYSTEM_RESET = struct.pack('B' * 4, 0x5A, 0x04, 0x02, 0x60) diff --git a/Tools/scripts/uploader.py b/Tools/scripts/uploader.py index 27a6875e1ca..f37121f577c 100755 --- a/Tools/scripts/uploader.py +++ b/Tools/scripts/uploader.py @@ -712,7 +712,7 @@ class uploader(object): try: report_crc = self.__recv_int() break - except Exception: + except Exception: # noqa: BLE001 continue if time.time() >= deadline: @@ -741,7 +741,7 @@ class uploader(object): else: try: self.extf_maxsize = self.__getInfo(uploader.INFO_EXTF_SIZE) - except Exception: + except Exception: # noqa: BLE001 print("Could not get external flash size, assuming 0") self.extf_maxsize = 0 self.__sync() @@ -754,7 +754,7 @@ class uploader(object): # Only run if we are trying to identify the board try: self.git_hash_bl = self.__getBootloaderSoftware() - except Exception: + except Exception: # noqa: BLE001 self.__sync() def dump_board_info(self): @@ -786,7 +786,7 @@ class uploader(object): x = x[::-1] # reverse the bytes print(binascii.hexlify(x).decode('Latin-1'), end='') # show user print('') - except Exception: + except Exception: # noqa: BLE001 # ignore bad character encodings pass @@ -901,7 +901,7 @@ class uploader(object): if len(ret) == 0: return None return " or ".join(ret) - except Exception as e: + except Exception as e: # noqa: BLE001 print("Failed to get name: %s" % str(e)) return None @@ -985,7 +985,7 @@ class uploader(object): try: self.port.baudrate = self.baudrate_flightstack[self.baudrate_flightstack_idx] - except Exception: + except Exception: # noqa: BLE001 return False return True @@ -1011,11 +1011,11 @@ class uploader(object): self.__send(uploader.NSH_REBOOT) self.port.flush() self.port.baudrate = self.baudrate_bootloader - except Exception: + except Exception: # noqa: BLE001 try: self.port.flush() self.port.baudrate = self.baudrate_bootloader - except Exception: + except Exception: # noqa: BLE001 pass return True @@ -1089,7 +1089,7 @@ def find_bootloader(up, port): print("Found board %x,%x bootloader rev %x on %s" % (up.board_type, up.board_rev, up.bl_rev, port)) return True - except Exception: + except Exception: # noqa: BLE001 pass reboot_sent = up.send_reboot() @@ -1204,7 +1204,7 @@ def main(): args.force_erase, args.identify) - except Exception as e: + except Exception as e: # noqa: BLE001 if not is_WSL and not is_WSL2 and "win32" not in _platform: # open failed, WSL must cycle through all ttyS* ports quickly but rate limit everything else print("Exception creating uploader: %s" % str(e))