laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/pysim/+/34697?usp=email )

Change subject: transport: do not catch exceptions in init_reader
......................................................................

transport: do not catch exceptions in init_reader

We currently catch any exceptions that may occur when the card reader is
initialized. Then we print the exception string or the exception type
when no string is available. However, a failure during the reader
initialization is usually a severe problem, so a traceback would provde
a lot of helpful information to debug the issue. So lets not catch any
exceptions at this level so that we get the full backtrace.

Related: OS#6210
Change-Id: I4c4807576fe63cf71a7d33b243a3f8fea0b7ff23
---
M pySim-prog.py
M pySim-read.py
M pySim-shell.py
M pySim/transport/__init__.py
4 files changed, 37 insertions(+), 35 deletions(-)

Approvals:
  fixeria: Looks good to me, but someone else must approve
  Jenkins Builder: Verified
  laforge: Looks good to me, approved




diff --git a/pySim-prog.py b/pySim-prog.py
index a16928c..2911b46 100755
--- a/pySim-prog.py
+++ b/pySim-prog.py
@@ -794,8 +794,6 @@

     # Init card reader driver
     sl = init_reader(opts)
-    if sl is None:
-        exit(1)

     # Create command layer
     scc = SimCardCommands(transport=sl)
diff --git a/pySim-read.py b/pySim-read.py
index bafaf26..d34ddc3 100755
--- a/pySim-read.py
+++ b/pySim-read.py
@@ -74,8 +74,6 @@

     # Init card reader driver
     sl = init_reader(opts)
-    if sl is None:
-        exit(1)

     # Create command layer
     scc = SimCardCommands(transport=sl)
diff --git a/pySim-shell.py b/pySim-shell.py
index 56655ba..afc7653 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -1015,8 +1015,6 @@

     # Init card reader driver
     sl = init_reader(opts, proactive_handler = Proact())
-    if sl is None:
-        exit(1)

     # Create a card handler (for bulk provisioning)
     if opts.card_handler_config:
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py
index 0b50a4f..581f8e5 100644
--- a/pySim/transport/__init__.py
+++ b/pySim/transport/__init__.py
@@ -292,35 +292,26 @@
     return arg_parser


-def init_reader(opts, **kwargs) -> Optional[LinkBase]:
+def init_reader(opts, **kwargs) -> LinkBase:
     """
     Init card reader driver
     """
-    sl = None  # type : :Optional[LinkBase]
-    try:
-        if opts.pcsc_dev is not None:
-            print("Using PC/SC reader interface")
-            from pySim.transport.pcsc import PcscSimLink
-            sl = PcscSimLink(opts.pcsc_dev, **kwargs)
-        elif opts.osmocon_sock is not None:
-            print("Using Calypso-based (OsmocomBB) reader interface")
-            from pySim.transport.calypso import CalypsoSimLink
-            sl = CalypsoSimLink(sock_path=opts.osmocon_sock, **kwargs)
-        elif opts.modem_dev is not None:
-            print("Using modem for Generic SIM Access (3GPP TS 27.007)")
-            from pySim.transport.modem_atcmd import ModemATCommandLink
-            sl = ModemATCommandLink(
-                device=opts.modem_dev, baudrate=opts.modem_baud, **kwargs)
-        else:  # Serial reader is default
-            print("Using serial reader interface")
-            from pySim.transport.serial import SerialSimLink
-            sl = SerialSimLink(device=opts.device,
-                               baudrate=opts.baudrate, **kwargs)
-        return sl
-    except Exception as e:
-        if str(e):
-            print("Card reader initialization failed with exception:\n" + 
str(e))
-        else:
-            print(
-                "Card reader initialization failed with an exception of 
type:\n" + str(type(e)))
-        return None
+    if opts.pcsc_dev is not None:
+        print("Using PC/SC reader interface")
+        from pySim.transport.pcsc import PcscSimLink
+        sl = PcscSimLink(opts.pcsc_dev, **kwargs)
+    elif opts.osmocon_sock is not None:
+        print("Using Calypso-based (OsmocomBB) reader interface")
+        from pySim.transport.calypso import CalypsoSimLink
+        sl = CalypsoSimLink(sock_path=opts.osmocon_sock, **kwargs)
+    elif opts.modem_dev is not None:
+        print("Using modem for Generic SIM Access (3GPP TS 27.007)")
+        from pySim.transport.modem_atcmd import ModemATCommandLink
+        sl = ModemATCommandLink(
+             device=opts.modem_dev, baudrate=opts.modem_baud, **kwargs)
+    else:  # Serial reader is default
+        print("Using serial reader interface")
+        from pySim.transport.serial import SerialSimLink
+        sl = SerialSimLink(device=opts.device,
+                           baudrate=opts.baudrate, **kwargs)
+    return sl

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/34697?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I4c4807576fe63cf71a7d33b243a3f8fea0b7ff23
Gerrit-Change-Number: 34697
Gerrit-PatchSet: 2
Gerrit-Owner: dexter <pma...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanits...@sysmocom.de>
Gerrit-Reviewer: laforge <lafo...@osmocom.org>
Gerrit-MessageType: merged

Reply via email to