From eda408fba3f6e3a78ba0316e0f1fa5d2ba386fe1 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 17 Jul 2024 19:28:05 +0200 Subject: [PATCH] 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 --- pySim/commands.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pySim/commands.py b/pySim/commands.py index 40b0980a..3f659eb8 100644 --- a/pySim/commands.py +++ b/pySim/commands.py @@ -334,8 +334,8 @@ class SimCardCommands: 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 @@ class SimCardCommands: 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: