From f1e1e729c4757931e28773ef034e0c614d8d7b82 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Thu, 23 Nov 2023 11:33:55 +0100 Subject: [PATCH] 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 --- pySim/app.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pySim/app.py b/pySim/app.py index 1711a1c7..b0df85f8 100644 --- a/pySim/app.py +++ b/pySim/app.py @@ -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