Skip to content

Commit eb3d128

Browse files
committed
handle all binary parsing errors
1 parent e750273 commit eb3d128

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

codeflash/verification/parse_test_output.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,45 @@ def parse_test_return_values_bin(file_location: Path, test_files: TestFiles, tes
4949
if not len_next_bytes:
5050
return test_results
5151
len_next = int.from_bytes(len_next_bytes, byteorder="big")
52-
try:
53-
encoded_test_name = file.read(len_next).decode("ascii")
54-
except Exception as e:
52+
encoded_test_bytes = file.read(len_next)
53+
if not encoded_test_bytes:
5554
if DEBUG_MODE:
56-
logger.exception(f"Failed to load test name. Exception: {e}")
55+
logger.warning("Failed to load test name")
5756
return test_results
57+
encoded_test_name = encoded_test_bytes.decode("ascii")
5858
duration_bytes = file.read(8)
59+
if not duration_bytes:
60+
if DEBUG_MODE:
61+
logger.warning("Failed to load test duration")
62+
return test_results
5963
duration = int.from_bytes(duration_bytes, byteorder="big")
6064
len_next_bytes = file.read(4)
6165
if not len_next_bytes:
6266
return test_results
6367
len_next = int.from_bytes(len_next_bytes, byteorder="big")
64-
try:
65-
test_pickle_bin = file.read(len_next)
66-
except Exception as e:
68+
test_pickle_bin = file.read(len_next)
69+
if not test_pickle_bin:
6770
if DEBUG_MODE:
68-
logger.exception(f"Failed to load pickle file. Exception: {e}")
71+
logger.warning("Failed to load pickle file.")
6972
return test_results
7073
loop_index_bytes = file.read(8)
74+
if not loop_index_bytes:
75+
if DEBUG_MODE:
76+
logger.warning("Failed to load loop index")
77+
return test_results
7178
loop_index = int.from_bytes(loop_index_bytes, byteorder="big")
7279
len_next_bytes = file.read(4)
80+
if not len_next_bytes:
81+
if DEBUG_MODE:
82+
logger.warning("Failed to load invocation id")
83+
return test_results
7384
len_next = int.from_bytes(len_next_bytes, byteorder="big")
74-
invocation_id = file.read(len_next).decode("ascii")
85+
invocation_id_bytes = file.read(len_next)
86+
if not invocation_id_bytes:
87+
if DEBUG_MODE:
88+
logger.warning("Failed to load invocation id bytes")
89+
return test_results
90+
invocation_id = invocation_id_bytes.decode("ascii")
7591

7692
invocation_id_object = InvocationId.from_str_id(encoded_test_name, invocation_id)
7793
test_file_path = file_path_from_module_name(

0 commit comments

Comments
 (0)