Skip to content

Commit

Permalink
code quality: do not use bare except (#1558)
Browse files Browse the repository at this point in the history
replace all uses of bare excepts with "except Exception" to avoid
catching exceptions like KeyboardInterrupt and SystemExit.
  • Loading branch information
jsiverskog committed May 17, 2023
1 parent ef9d33d commit 1a61989
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 14 deletions.
3 changes: 1 addition & 2 deletions pyocd/commands/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ def modify(self, args):
raise exceptions.CommandError("no clock frequency provided")
try:
freq_Hz = convert_frequency(args[0])
except:
except Exception:
raise exceptions.CommandError("invalid frequency")
self.context.probe.set_clock(freq_Hz)
if self.context.probe.wire_protocol == DebugProbe.Protocol.SWD:
Expand Down Expand Up @@ -837,4 +837,3 @@ def modify(self, args):
raise exceptions.CommandError("invalid reset type")

self.context.session.options['reset_type'] = new_reset_type

4 changes: 1 addition & 3 deletions pyocd/debug/elf/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _build_line_search_tree(self):
if fromAddr == toAddr:
toAddr += 1
self.line_tree.addi(fromAddr, toAddr, info)
except:
except Exception:
LOG.debug("Problematic lineprog:")
self._dump_lineprog(lineprog)
raise
Expand Down Expand Up @@ -234,5 +234,3 @@ def dump_subprograms(self):
high_pc = 0xffffffff
filename = os.path.basename(prog._parent.attributes['DW_AT_name'].value.replace('\\', '/'))
LOG.debug("%s%s%08x %08x %s", name, (' ' * (50-len(name))), low_pc, high_pc, filename)


2 changes: 1 addition & 1 deletion pyocd/probe/picoprobe.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def flush_queue(self):
'B', self._qulen.to_bytes(4, 'little'))
try:
self._wr_ep.write(self._queue)
except:
except Exception:
# Anything from the USB layer assumes probe is no longer connected
raise exceptions.ProbeDisconnected(
'Cannot access probe ' + self._probe_id)
Expand Down
3 changes: 1 addition & 2 deletions test/commands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def test_command(cmd, print_result=True):
try:
print("\nTEST: %s" % cmd)
context.process_command_line(cmd)
except:
except Exception:
if print_result:
print("TEST FAILED")
failed_commands.append(cmd)
Expand Down Expand Up @@ -285,4 +285,3 @@ def test_command(cmd, print_result=True):
logging.basicConfig(level=level)
DAPAccess.set_args(args.daparg)
commands_test(args.uid)

4 changes: 2 additions & 2 deletions test/gdb_test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def run_test():
print("Test completed with %i errors" % fail_count)
else:
print("Test completed successfully")
except:
except Exception:
print("Main Error:")
traceback.print_exc()
fail_count += 1
Expand Down Expand Up @@ -528,7 +528,7 @@ def run_generator(event):
stop_delay = 0
try:
stop_delay = generator.send(event)
except:
except Exception:
print("Error")
traceback.print_exc()
interrupt_arg = {"aborted": False}
Expand Down
3 changes: 1 addition & 2 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def emit(self, record):
try:
message = self.format(record)
self.stream.write(six.u(message + "\n"))
except:
except Exception:
self.handleError(record)

class TestResult(object):
Expand Down Expand Up @@ -308,4 +308,3 @@ def all_tests_pass(result_list, ignored=[]):
if len(result_list) <= 0:
passed = False
return passed

3 changes: 1 addition & 2 deletions test/user_script_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_command(cmd):
try:
print("\nTEST: %s" % cmd)
context.process_command_line(cmd)
except:
except Exception:
print("TEST FAILED")
traceback.print_exc(file=sys.stdout)
return False
Expand Down Expand Up @@ -140,4 +140,3 @@ def test_command(cmd):
session = ConnectHelper.session_with_chosen_probe(**get_session_options())
test = UserScriptTest()
result = [test.run(session.board)]

0 comments on commit 1a61989

Please sign in to comment.