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

14
lib/upload-lib.js generated
View file

@ -410,9 +410,17 @@ async function uploadFiles(sarifPath, checkoutPath, category, features, logger)
logger.startGroup("Uploading results");
logger.info(`Processing sarif files: ${JSON.stringify(sarifFiles)}`);
const gitHubVersion = await (0, api_client_1.getGitHubVersion)();
// Validate that the files we were asked to upload are all valid SARIF files
for (const file of sarifFiles) {
validateSarifFileSchema(file, logger);
try {
// Validate that the files we were asked to upload are all valid SARIF files
for (const file of sarifFiles) {
validateSarifFileSchema(file, logger);
}
}
catch (e) {
if (e instanceof SyntaxError) {
throw new InvalidSarifUploadError(e.message);
}
throw e;
}
let sarif = await combineSarifFilesUsingCLI(sarifFiles, gitHubVersion, features, logger);
sarif = filterAlertsByDiffRange(logger, sarif);