laforge submitted this change.
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(-)
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 change 37622. To unsubscribe, or for help writing mail filters, visit settings.