review-comments: nest validateSariFileSchema into try-catch block to better discriminate error thrown

This commit is contained in:
Fotis Koutoulakis (@NlightNFotis) 2025-04-02 19:06:31 +01:00
parent 498c7f37e8
commit 676a422916
6 changed files with 25 additions and 24 deletions

View file

@ -80,15 +80,8 @@ async function run() {
await sendSuccessStatusReport(startedAt, uploadResult.statusReport, logger);
}
catch (unwrappedError) {
// This is testing the error to check if it belongs to one of two categories we reliably
// know to be configuration errors in certain cases.
const configurationErrorCandidate =
// There was a problem uploading the SARIF file (perhaps rejected by the backend)
unwrappedError instanceof upload_lib.InvalidSarifUploadError ||
// There was a problem validating the JSON (SARIF) file.
unwrappedError instanceof SyntaxError;
const error = (0, status_report_1.isThirdPartyAnalysis)(status_report_1.ActionName.UploadSarif) &&
configurationErrorCandidate
unwrappedError instanceof upload_lib.InvalidSarifUploadError
? new util_1.ConfigurationError(unwrappedError.message)
: (0, util_1.wrapError)(unwrappedError);
const message = error.message;