@@ -119,18 +119,29 @@ def print_changes(current_commit: str, past_commit: str):
119
119
if "delta" in path :
120
120
continue
121
121
122
+ # Skip files outside cve
123
+ if "cve" not in path :
124
+ continue
125
+
122
126
if type == "D" :
123
127
print (f"Deleted: { Path (path ).stem } " , file = sys .stderr )
124
128
else :
125
- current = json_at_commit (path , current_commit )
126
- modified = current ["cveMetadata" ]["dateUpdated" ]
127
- modified = re .sub (r"\..*" , "" , modified )
128
- modified = re .sub (r"T" , " " , modified )
129
- cve = current ["cveMetadata" ]["cveId" ]
129
+ try :
130
+ current = json_at_commit (path , current_commit )
131
+ modified = current ["cveMetadata" ]["dateUpdated" ]
132
+ modified = re .sub (r"\..*" , "" , modified )
133
+ modified = re .sub (r"T" , " " , modified )
134
+ cve = current ["cveMetadata" ]["cveId" ]
135
+ except (KeyError , TypeError ):
136
+ continue
130
137
131
138
if type == "M" :
132
- past = json_at_commit (path , past_commit )
133
- past_cvss = cvss31score (past )
139
+ try :
140
+ past = json_at_commit (path , past_commit )
141
+ past_cvss = cvss31score (past )
142
+ except TypeError :
143
+ print (f"Unexpected structure in (past) { path } " , file = sys .stderr )
144
+ past_cvss = " "
134
145
else :
135
146
past_cvss = " "
136
147
@@ -173,21 +184,33 @@ def print_changes_color(current_commit: str, past_commit: str):
173
184
if "delta" in path :
174
185
continue
175
186
187
+ # Skip files outside cve
188
+ if "cve" not in path :
189
+ continue
190
+
176
191
if type == "D" :
177
192
print (
178
193
f"{ ansi ('red' )} Deleted: { Path (path ).stem } { ansi ('end' )} " , file = sys .stderr
179
194
)
180
195
else :
181
- current = json_at_commit (path , current_commit )
182
- modified = current ["cveMetadata" ]["dateUpdated" ]
183
- modified = re .sub (r"\..*" , "" , modified )
184
- modified = re .sub (r"T" , " " , modified )
185
- cve = current ["cveMetadata" ]["cveId" ]
196
+ try :
197
+ current = json_at_commit (path , current_commit )
198
+ modified = current ["cveMetadata" ]["dateUpdated" ]
199
+ modified = re .sub (r"\..*" , "" , modified )
200
+ modified = re .sub (r"T" , " " , modified )
201
+ cve = current ["cveMetadata" ]["cveId" ]
202
+ except (KeyError , TypeError ):
203
+ print (f"Unexpected structure in { path } " , file = sys .stderr )
204
+ continue
186
205
187
206
if type == "M" :
188
207
cve = f"{ ansi ('bright_blue' )} { cve } { ansi ('end' )} "
189
- past = json_at_commit (path , past_commit )
190
- past_cvss = cvss31score (past )
208
+ try :
209
+ past = json_at_commit (path , past_commit )
210
+ past_cvss = cvss31score (past )
211
+ except TypeError :
212
+ print (f"Unexpected structure in (past) { path } " , file = sys .stderr )
213
+ past_cvss = f" "
191
214
else :
192
215
cve = f"{ ansi ('bright_cyan' )} { cve } { ansi ('end' )} "
193
216
past_cvss = " "
@@ -300,7 +323,9 @@ def json_at_commit(path: Path, commit: str) -> dict:
300
323
data = json .loads (result .stdout .decode ("utf-8" ))
301
324
return data
302
325
except IOError :
303
- print (f"Could not open { path } " , file = sys .stderr )
326
+ print (f"Could not open { commit } :{ path } " , file = sys .stderr )
327
+ except json .decoder .JSONDecodeError :
328
+ print (f"Could not parse { commit } :{ path } " , file = sys .stderr )
304
329
305
330
306
331
def cvelist_repo ():
0 commit comments