Skip to content

Commit c83f5df

Browse files
Merge pull request #1432 from codeflash-ai/catch-a-unicodedecode-exception
Catch one more binary file exception
2 parents 0b2ff7c + eb3d128 commit c83f5df

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

codeflash/verification/parse_test_output.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +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-
encoded_test_name = file.read(len_next).decode("ascii")
52+
encoded_test_bytes = file.read(len_next)
53+
if not encoded_test_bytes:
54+
if DEBUG_MODE:
55+
logger.warning("Failed to load test name")
56+
return test_results
57+
encoded_test_name = encoded_test_bytes.decode("ascii")
5358
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
5463
duration = int.from_bytes(duration_bytes, byteorder="big")
5564
len_next_bytes = file.read(4)
5665
if not len_next_bytes:
5766
return test_results
5867
len_next = int.from_bytes(len_next_bytes, byteorder="big")
59-
try:
60-
test_pickle_bin = file.read(len_next)
61-
except Exception as e:
68+
test_pickle_bin = file.read(len_next)
69+
if not test_pickle_bin:
6270
if DEBUG_MODE:
63-
logger.exception(f"Failed to load pickle file. Exception: {e}")
71+
logger.warning("Failed to load pickle file.")
6472
return test_results
6573
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
6678
loop_index = int.from_bytes(loop_index_bytes, byteorder="big")
6779
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
6884
len_next = int.from_bytes(len_next_bytes, byteorder="big")
69-
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")
7091

7192
invocation_id_object = InvocationId.from_str_id(encoded_test_name, invocation_id)
7293
test_file_path = file_path_from_module_name(

0 commit comments

Comments
 (0)