laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/37622?usp=email )


Change subject: pySim.commands: Don't convert SwMatchError to ValueError
......................................................................

pySim.commands: Don't convert SwMatchError to ValueError

In the read and write command implementations, we used to catch
lower-layer exceptions (usually SwMatchError) and "translate" that into
a value error, only to add more information to the exception.  This
meant that higher-layer code could no longer detect this was actually
a SwMatchError exception type.

Let's instead use the add_note() method to amend the existing exception,
rather than raising a new one of different type.

Change-Id: Ic94d0fe60a8a5e15aade56ec418192ecf31ac5e7
---
M pySim/commands.py
1 file changed, 22 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/22/37622/1

diff --git a/pySim/commands.py b/pySim/commands.py
index 40b0980..3f659eb 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -334,8 +334,8 @@
             try:
                 data, sw = self.send_apdu_checksw(pdu)
             except Exception as e:
-                raise ValueError('%s, failed to read (offset %d)' %
-                                 (str_sanitize(str(e)), offset)) from e
+                e.add_note('failed to read (offset %d)' % offset)
+                raise e
             total_data += data
             chunk_offset += chunk_len
         return total_data, sw
@@ -394,8 +394,8 @@
             try:
                 chunk_data, chunk_sw = self.send_apdu_checksw(pdu)
             except Exception as e:
-                raise ValueError('%s, failed to write chunk (chunk_offset %d, 
chunk_len %d)' %
-                                 (str_sanitize(str(e)), chunk_offset, 
chunk_len)) from e
+                e.add_note('failed to write chunk (chunk_offset %d, chunk_len 
%d)' % (chunk_offset, chunk_len))
+                raise e
             total_data += data
             chunk_offset += chunk_len
         if verify:

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/37622?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: Ic94d0fe60a8a5e15aade56ec418192ecf31ac5e7
Gerrit-Change-Number: 37622
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <[email protected]>
Gerrit-MessageType: newchange

Reply via email to