Merge #373: Avoided bare except

44dabcfa80 Avoided bare expect (Ferdinando Ametrano)

Pull request description:

  Using a bare `except:` is not a good coding practice: it catches all exceptions inheriting from `BaseException`, including `SystemExit`, `KeyboardInterrupt`, and `GeneratorExit` (which is not an error and should not normally be caught by user code).
  ```
  BaseException
    - Exception
    - GeneratorExit
    - KeyboardInterrupt
    - SystemExit
  ```
  This patch is sub-optimal because only specific exceptions should be catched... anyway, in situations where one wants to catch all “normal” exceptions, at least restrict to explicitly catch the `Exception` base class, instead of implicitly catching any `BaseException`.

ACKs for top commit:
  achow101:
    ACK 44dabcfa80

Tree-SHA512: 220dc4be1c47958e3727205d9cbb03069a49108ce697983c1967cf04f980cf3f607399e9a2c9e511d270f13154aa85a1cf9c92cfd0681f7ba56622134f663dd1
This commit is contained in:
Andrew Chow 2020-08-25 13:35:55 -04:00
commit db672d048b
No known key found for this signature in database
GPG Key ID: 17565732E08E5E41
10 changed files with 16 additions and 15 deletions

View File

@ -69,7 +69,7 @@ def find_device(password='', device_type=None, fingerprint=None, expert=False):
client.close()
continue
return client
except:
except Exception:
if client:
client.close()
pass # Ignore things we wouldn't get fingerprints for

View File

@ -84,7 +84,7 @@ class btchip:
self.scriptBlockLength = 50
else:
self.scriptBlockLength = 255
except:
except Exception:
pass
def getWalletPublicKey(self, path, showOnScreen=False, segwit=False, segwitNative=False, cashAddr=False):
@ -271,7 +271,7 @@ class btchip:
response = self.dongle.exchange(bytearray(apdu))
offset += dataLength
alternateEncoding = True
except:
except Exception:
pass
if not alternateEncoding:
apdu = [ self.BTCHIP_CLA, self.BTCHIP_INS_HASH_INPUT_FINALIZE, 0x02, 0x00 ]

View File

@ -142,7 +142,7 @@ class HIDDongleHIDAPI(Dongle, DongleWait):
if self.opened:
try:
self.device.close()
except:
except Exception:
pass
self.opened = False
@ -155,7 +155,7 @@ class DongleServer(Dongle):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
self.socket.connect((self.server, self.port))
except:
except Exception:
raise BTChipException("Proxy connection failed")
def exchange(self, apdu, timeout=20000):
@ -175,5 +175,5 @@ class DongleServer(Dongle):
def close(self):
try:
self.socket.close()
except:
except Exception:
pass

View File

@ -162,7 +162,7 @@ class ColdcardDevice:
except CCProtoError:
if expect_errors: raise
raise
except:
except Exception:
#print("Corrupt response: %r" % resp)
raise
@ -376,7 +376,8 @@ class UnixSimulatorPipe:
self.pipe.close()
try:
os.unlink(self.pipe_name)
except: pass
except Exception:
pass
def get_serial_number_string(self):
return 'simulator'

View File

@ -631,7 +631,7 @@ def enumerate(password=''):
dev.send_recv(b'{"device" : "info"}')
devices.append({'path': b'udp:127.0.0.1:35345', 'interface_number': 0})
dev.close()
except:
except Exception:
pass
for d in devices:
if ('interface_number' in d and d['interface_number'] == 0

View File

@ -460,7 +460,7 @@ class TrezorClient(HardwareWalletClient):
multisig=multisig,
)
return {'address': address}
except:
except Exception:
pass
raise BadArgumentError("No path supplied matched device keys")
@ -543,7 +543,7 @@ class TrezorClient(HardwareWalletClient):
self._check_unlocked()
try:
device.apply_settings(self.client, use_passphrase=not self.client.features.passphrase_protection)
except:
except Exception:
if self.type == 'Keepkey':
print('Confirm the action by entering your PIN', file=sys.stderr)
print('Use \'sendpin\' to provide the number positions for the PIN as displayed on your device\'s screen', file=sys.stderr)

View File

@ -149,7 +149,7 @@ class TrezorClient:
try:
passphrase = self.ui.get_passphrase()
except:
except Exception:
self.call_raw(messages.Cancel())
raise

View File

@ -129,7 +129,7 @@ class WebUsbTransport(ProtocolBasedTransport):
# non-functional.
dev.getProduct()
devices.append(WebUsbTransport(dev))
except:
except Exception:
pass
return devices

View File

@ -31,7 +31,7 @@ def coldcard_test_suite(simulator, rpc, userpass, interface):
break
if found:
break
except:
except Exception:
pass
time.sleep(0.5)
# Cleanup

View File

@ -28,7 +28,7 @@ def digitalbitbox_test_suite(simulator, rpc, userpass, interface):
reply = send_plain(b'{"password":"0000"}', dev)
if 'error' not in reply:
break
except:
except Exception:
pass
time.sleep(0.5)
# Cleanup