Skip to content

Commit f1424ff

Browse files
committed
stats_engine: Skip files on UnicodeDecodeError
TODO: Find a better solution for this and handle the error.
1 parent 970462d commit f1424ff

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

stats_engine.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,12 @@ def collect_stats(kernel_repo, cve_patch):
138138
if not os.path.exists(file_path):
139139
continue
140140

141-
fp_contents = [line.rstrip('\n') for line in
142-
open(file_path, 'r') if line.strip()]
141+
try:
142+
fp_contents = [line.rstrip('\n') for line in
143+
open(file_path, 'r') if line.strip()]
144+
except UnicodeDecodeError:
145+
print("[E] Failed to read file: " + file_path + ", skipping!")
146+
continue
143147

144148
# we need this array so we can check the above block
145149
all_added = []
@@ -191,8 +195,12 @@ def collect_stats(kernel_repo, cve_patch):
191195
if not os.path.exists(file_path):
192196
continue
193197

194-
fp_contents = [line.rstrip('\n') for line in
195-
open(file_path, 'r') if line.strip()]
198+
try:
199+
fp_contents = [line.rstrip('\n') for line in
200+
open(file_path, 'r') if line.strip()]
201+
except UnicodeDecodeError:
202+
print("[E] Failed to read file: " + file_path + ", skipping!")
203+
continue
196204

197205
for i in range(0, len(fp_contents)):
198206
lines = fp_contents[i:i+2]

0 commit comments

Comments
 (0)