app: do not catch exceptions in init_card

The function init_card catches all exceptions and then returns None
objects for card or rs in case of an error. This does not fit in the
style we pursue in pySim. This is in particular true for library
functions. We want those functions to raise exceptions when something is
wrong, so that we can catch the exception at top level. Let's fix this
for init_card now.

Related: OS#6271
Change-Id: I581125d8273ef024f6dbf3a5db6116be15c5c95d
This commit is contained in:
Philipp Maier
2023-11-23 11:33:55 +01:00
parent 40ef226030
commit f1e1e729c4

View File

@@ -55,14 +55,7 @@ def init_card(sl: LinkBase) -> Tuple[RuntimeState, SimCardBase]:
# Wait up to three seconds for a card in reader and try to detect
# the card type.
print("Waiting for card...")
try:
sl.wait_for_card(3)
except NoCardError:
print("No card detected!")
return None, None
except:
print("Card not readable!")
return None, None
sl.wait_for_card(3)
generic_card = False
card = card_detect(scc)
@@ -73,6 +66,10 @@ def init_card(sl: LinkBase) -> Tuple[RuntimeState, SimCardBase]:
profile = CardProfile.pick(scc)
if profile is None:
# It is not an unrecoverable error in case profile detection fails. It
# just means that pySim was unable to recognize the card profile. This
# may happen in particular with unprovisioned cards that do not have
# any files on them yet.
print("Unsupported card type!")
return None, card