Skip to content

Commit

Permalink
move check to calling function
Browse files Browse the repository at this point in the history
DISABLE_DUPLICATE_LOCATION_FIX - this is to avoid needless crashes on
large sarif files
  • Loading branch information
Stephan Brandauer committed May 24, 2023
1 parent 1245696 commit 3100e1e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3100e1e

Please sign in to comment.