forked from public/pysim
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
This commit is contained in:
@@ -334,8 +334,8 @@ class SimCardCommands:
|
|||||||
try:
|
try:
|
||||||
data, sw = self.send_apdu_checksw(pdu)
|
data, sw = self.send_apdu_checksw(pdu)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError('%s, failed to read (offset %d)' %
|
e.add_note('failed to read (offset %d)' % offset)
|
||||||
(str_sanitize(str(e)), offset)) from e
|
raise e
|
||||||
total_data += data
|
total_data += data
|
||||||
chunk_offset += chunk_len
|
chunk_offset += chunk_len
|
||||||
return total_data, sw
|
return total_data, sw
|
||||||
@@ -394,8 +394,8 @@ class SimCardCommands:
|
|||||||
try:
|
try:
|
||||||
chunk_data, chunk_sw = self.send_apdu_checksw(pdu)
|
chunk_data, chunk_sw = self.send_apdu_checksw(pdu)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError('%s, failed to write chunk (chunk_offset %d, chunk_len %d)' %
|
e.add_note('failed to write chunk (chunk_offset %d, chunk_len %d)' % (chunk_offset, chunk_len))
|
||||||
(str_sanitize(str(e)), chunk_offset, chunk_len)) from e
|
raise e
|
||||||
total_data += data
|
total_data += data
|
||||||
chunk_offset += chunk_len
|
chunk_offset += chunk_len
|
||||||
if verify:
|
if verify:
|
||||||
|
|||||||
Reference in New Issue
Block a user