mirror of
https://github.com/github/codeql-action.git
synced 2026-10-30 17:39:50 +00:00
Display better error message on invalid sarif
Specifically, some third party tools do not include a `results` block for runs when there is an error. This change adds a more explicit error message for this situation.
This commit is contained in:
committed by
Andrew Eisenberg
parent
ffd96b38fb
commit
08fae3caba
@@ -176,7 +176,20 @@ function getSarifFilePaths(sarifPath: string) {
|
||||
// Counts the number of results in the given SARIF file
|
||||
export function countResultsInSarif(sarif: string): number {
|
||||
let numResults = 0;
|
||||
for (const run of JSON.parse(sarif).runs) {
|
||||
let parsedSarif;
|
||||
try {
|
||||
parsedSarif = JSON.parse(sarif);
|
||||
} catch (e) {
|
||||
throw new Error(`Invalid SARIF. JSON syntax error: ${e.message}`);
|
||||
}
|
||||
if (!Array.isArray(parsedSarif.runs)) {
|
||||
throw new Error("Invalid SARIF. Missing 'runs' array.");
|
||||
}
|
||||
|
||||
for (const run of parsedSarif.runs) {
|
||||
if (!Array.isArray(run.results)) {
|
||||
throw new Error("Invalid SARIF. Missing 'results' array in run.");
|
||||
}
|
||||
numResults += run.results.length;
|
||||
}
|
||||
return numResults;
|
||||
|
||||
Reference in New Issue
Block a user