Skip to content

Commit

Permalink
Remove err log if not supported scan (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas authored Jun 21, 2023
1 parent a4e254f commit d29b726
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions src/main/scanLogic/scanRunners/binaryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,27 +276,45 @@ export abstract class BinaryRunner {
})
);
}
let hadError: boolean = false;
let exeErr: Error | undefined;
await Promise.all(runs)
.catch(err => {
hadError = true;
exeErr = err;
throw err;
})
// Collect log if exist
.finally(() => this.copyRunLogToFolder(args, hadError));
.finally(() => this.handleExecutionLog(args, exeErr));
return aggResponse;
}

private handleExecutionLog(args: RunArgs, exeErr: Error | undefined) {
let hadError: boolean = exeErr !== undefined;
let logPath: string | undefined = this.copyRunLogToFolder(args, hadError);
if (logPath && !(exeErr instanceof NotSupportedError)) {
this._logManager.logMessage(
'AnalyzerManager run ' +
this._type +
' on ' +
args.getRoots() +
' ended ' +
(hadError ? 'with error' : 'successfully') +
', scan log was generated at ' +
logPath,
hadError ? 'ERR' : 'DEBUG'
);
}
}

/**
* Copy a file that includes 'log' in its name from a given folder to the logs folder
* @param arg - the run arguments that related this log
* @param hadError - if true, will log result as error, otherwise success.
* @param copyToDirectory - optional destination to copy the log
*/
private copyRunLogToFolder(args: RunArgs, hadError: boolean, copyToDirectory: string = ScanUtils.getLogsPath()) {
private copyRunLogToFolder(args: RunArgs, hadError: boolean, copyToDirectory: string = ScanUtils.getLogsPath()): string | undefined {
let logFile: string | undefined = fs.readdirSync(args.directory).find(fileName => fileName.toLowerCase().includes('log'));
if (!logFile) {
return;
return undefined;
}

let roots: string[] = args.getRoots();
Expand All @@ -307,17 +325,8 @@ export abstract class BinaryRunner {

fs.copyFileSync(path.join(args.directory, logFile), logFinalPath);
LogUtils.cleanUpOldLogs();
this._logManager.logMessage(
'AnalyzerManager run ' +
this._type +
' on ' +
roots +
' ended ' +
(hadError ? 'with error' : 'successfully') +
', scan log was generated at ' +
logFinalPath,
hadError ? 'ERR' : 'DEBUG'
);

return logFinalPath;
}

/**
Expand Down

0 comments on commit d29b726

Please sign in to comment.