Skip to content

Commit 1a61989

Browse files
authored
code quality: do not use bare except (#1558)
replace all uses of bare excepts with "except Exception" to avoid catching exceptions like KeyboardInterrupt and SystemExit.
1 parent ef9d33d commit 1a61989

File tree

7 files changed

+8
-14
lines changed

7 files changed

+8
-14
lines changed

pyocd/commands/values.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ def modify(self, args):
723723
raise exceptions.CommandError("no clock frequency provided")
724724
try:
725725
freq_Hz = convert_frequency(args[0])
726-
except:
726+
except Exception:
727727
raise exceptions.CommandError("invalid frequency")
728728
self.context.probe.set_clock(freq_Hz)
729729
if self.context.probe.wire_protocol == DebugProbe.Protocol.SWD:
@@ -837,4 +837,3 @@ def modify(self, args):
837837
raise exceptions.CommandError("invalid reset type")
838838

839839
self.context.session.options['reset_type'] = new_reset_type
840-

pyocd/debug/elf/decoder.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def _build_line_search_tree(self):
202202
if fromAddr == toAddr:
203203
toAddr += 1
204204
self.line_tree.addi(fromAddr, toAddr, info)
205-
except:
205+
except Exception:
206206
LOG.debug("Problematic lineprog:")
207207
self._dump_lineprog(lineprog)
208208
raise
@@ -234,5 +234,3 @@ def dump_subprograms(self):
234234
high_pc = 0xffffffff
235235
filename = os.path.basename(prog._parent.attributes['DW_AT_name'].value.replace('\\', '/'))
236236
LOG.debug("%s%s%08x %08x %s", name, (' ' * (50-len(name))), low_pc, high_pc, filename)
237-
238-

pyocd/probe/picoprobe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def flush_queue(self):
136136
'B', self._qulen.to_bytes(4, 'little'))
137137
try:
138138
self._wr_ep.write(self._queue)
139-
except:
139+
except Exception:
140140
# Anything from the USB layer assumes probe is no longer connected
141141
raise exceptions.ProbeDisconnected(
142142
'Cannot access probe ' + self._probe_id)

test/commands_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def test_command(cmd, print_result=True):
228228
try:
229229
print("\nTEST: %s" % cmd)
230230
context.process_command_line(cmd)
231-
except:
231+
except Exception:
232232
if print_result:
233233
print("TEST FAILED")
234234
failed_commands.append(cmd)
@@ -285,4 +285,3 @@ def test_command(cmd, print_result=True):
285285
logging.basicConfig(level=level)
286286
DAPAccess.set_args(args.daparg)
287287
commands_test(args.uid)
288-

test/gdb_test_script.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def run_test():
481481
print("Test completed with %i errors" % fail_count)
482482
else:
483483
print("Test completed successfully")
484-
except:
484+
except Exception:
485485
print("Main Error:")
486486
traceback.print_exc()
487487
fail_count += 1
@@ -528,7 +528,7 @@ def run_generator(event):
528528
stop_delay = 0
529529
try:
530530
stop_delay = generator.send(event)
531-
except:
531+
except Exception:
532532
print("Error")
533533
traceback.print_exc()
534534
interrupt_arg = {"aborted": False}

test/test_util.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def emit(self, record):
196196
try:
197197
message = self.format(record)
198198
self.stream.write(six.u(message + "\n"))
199-
except:
199+
except Exception:
200200
self.handleError(record)
201201

202202
class TestResult(object):
@@ -308,4 +308,3 @@ def all_tests_pass(result_list, ignored=[]):
308308
if len(result_list) <= 0:
309309
passed = False
310310
return passed
311-

test/user_script_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_command(cmd):
9898
try:
9999
print("\nTEST: %s" % cmd)
100100
context.process_command_line(cmd)
101-
except:
101+
except Exception:
102102
print("TEST FAILED")
103103
traceback.print_exc(file=sys.stdout)
104104
return False
@@ -140,4 +140,3 @@ def test_command(cmd):
140140
session = ConnectHelper.session_with_chosen_probe(**get_session_options())
141141
test = UserScriptTest()
142142
result = [test.run(session.board)]
143-

0 commit comments

Comments
 (0)