Skip to content

Commit 3100e1e

Browse files
author
Stephan Brandauer
committed
move check to calling function
DISABLE_DUPLICATE_LOCATION_FIX - this is to avoid needless crashes on large sarif files
1 parent 1245696 commit 3100e1e

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

src/util.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -818,13 +818,6 @@ export function fixInvalidNotifications(
818818
sarif: SarifFile,
819819
logger: Logger
820820
): SarifFile {
821-
if (process.env[CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX] === "true") {
822-
logger.info(
823-
"SARIF notification object duplicate location fix disabled by the " +
824-
`${CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX} environment variable.`
825-
);
826-
return sarif;
827-
}
828821
if (!Array.isArray(sarif.runs)) {
829822
return sarif;
830823
}
@@ -888,9 +881,17 @@ export function fixInvalidNotificationsInFile(
888881
outputPath: string,
889882
logger: Logger
890883
): void {
891-
let sarif = JSON.parse(fs.readFileSync(inputPath, "utf8")) as SarifFile;
892-
sarif = fixInvalidNotifications(sarif, logger);
893-
fs.writeFileSync(outputPath, JSON.stringify(sarif));
884+
if (process.env[CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX] === "true") {
885+
logger.info(
886+
"SARIF notification object duplicate location fix disabled by the " +
887+
`${CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX} environment variable.`
888+
);
889+
fs.renameSync(inputPath, outputPath);
890+
} else {
891+
let sarif = JSON.parse(fs.readFileSync(inputPath, "utf8")) as SarifFile;
892+
sarif = fixInvalidNotifications(sarif, logger);
893+
fs.writeFileSync(outputPath, JSON.stringify(sarif));
894+
}
894895
}
895896

896897
export function wrapError(error: unknown): Error {

0 commit comments

Comments
 (0)