Tolerate unexpected processing statuses for red SARIF uploads

This commit is contained in:
Henry Mercer 2023-06-14 14:09:13 +01:00
parent b8f204c619
commit 4d7934a07c
3 changed files with 27 additions and 17 deletions

19
lib/upload-lib.js generated
View file

@ -361,14 +361,19 @@ function handleProcessingResultForUnsuccessfulExecution(response, status, logger
logger.debug("Successfully uploaded a SARIF file for the unsuccessful execution. Received expected " +
'"unsuccessful execution" error, and no other errors.');
}
else if (status === "failed") {
logger.warning(`Failed to upload a SARIF file for the unsuccessful execution. Code scanning status ` +
`information for the repository may be out of date as a result. Processing errors: ${response.data.errors}`);
}
else if (status === "complete") {
// There is a known transient issue with the code scanning API where it sometimes reports
// `complete` for an unsuccessful execution submission.
logger.debug('Encountered no processing errors, but expected to receive an "unsuccessful execution" ' +
"error. This is a known transient issue with the code scanning API, and does not " +
"typically mean that code scanning status information will be out of date.");
}
else {
const shortMessage = "Failed to upload a SARIF file for the unsuccessful execution. Code scanning status " +
"information for the repository may be out of date as a result.";
const longMessage = shortMessage + status === "failed"
? ` Processing errors: ${response.data.errors}`
: ' Encountered no processing errors, but expected to receive an "unsuccessful execution" error.';
logger.debug(longMessage);
throw new Error(shortMessage);
util.assertNever(status);
}
}
function validateUniqueCategory(sarif) {

File diff suppressed because one or more lines are too long

View file

@ -508,16 +508,21 @@ function handleProcessingResultForUnsuccessfulExecution(
"Successfully uploaded a SARIF file for the unsuccessful execution. Received expected " +
'"unsuccessful execution" error, and no other errors.'
);
} else if (status === "failed") {
logger.warning(
`Failed to upload a SARIF file for the unsuccessful execution. Code scanning status ` +
`information for the repository may be out of date as a result. Processing errors: ${response.data.errors}`
);
} else if (status === "complete") {
// There is a known transient issue with the code scanning API where it sometimes reports
// `complete` for an unsuccessful execution submission.
logger.debug(
'Encountered no processing errors, but expected to receive an "unsuccessful execution" ' +
"error. This is a known transient issue with the code scanning API, and does not " +
"typically mean that code scanning status information will be out of date."
);
} else {
const shortMessage =
"Failed to upload a SARIF file for the unsuccessful execution. Code scanning status " +
"information for the repository may be out of date as a result.";
const longMessage =
shortMessage + status === "failed"
? ` Processing errors: ${response.data.errors}`
: ' Encountered no processing errors, but expected to receive an "unsuccessful execution" error.';
logger.debug(longMessage);
throw new Error(shortMessage);
util.assertNever(status);
}
}