From 3100e1e35432a42f842717327af62fe23049a855 Mon Sep 17 00:00:00 2001 From: Stephan Brandauer Date: Wed, 24 May 2023 11:46:19 +0000 Subject: [PATCH] move check to calling function DISABLE_DUPLICATE_LOCATION_FIX - this is to avoid needless crashes on large sarif files --- src/util.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/util.ts b/src/util.ts index edfc21978..824884336 100644 --- a/src/util.ts +++ b/src/util.ts @@ -818,13 +818,6 @@ export function fixInvalidNotifications( sarif: SarifFile, logger: Logger ): SarifFile { - if (process.env[CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX] === "true") { - logger.info( - "SARIF notification object duplicate location fix disabled by the " + - `${CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX} environment variable.` - ); - return sarif; - } if (!Array.isArray(sarif.runs)) { return sarif; } @@ -888,9 +881,17 @@ export function fixInvalidNotificationsInFile( outputPath: string, logger: Logger ): void { - let sarif = JSON.parse(fs.readFileSync(inputPath, "utf8")) as SarifFile; - sarif = fixInvalidNotifications(sarif, logger); - fs.writeFileSync(outputPath, JSON.stringify(sarif)); + if (process.env[CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX] === "true") { + logger.info( + "SARIF notification object duplicate location fix disabled by the " + + `${CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX} environment variable.` + ); + fs.renameSync(inputPath, outputPath); + } else { + let sarif = JSON.parse(fs.readFileSync(inputPath, "utf8")) as SarifFile; + sarif = fixInvalidNotifications(sarif, logger); + fs.writeFileSync(outputPath, JSON.stringify(sarif)); + } } export function wrapError(error: unknown): Error {