throw on non zero exit code from workers

This commit is contained in:
Volodymyr Smirnov 2020-10-22 09:28:28 +03:00
parent d4703df14d
commit 46974066a4

View File

@ -21,6 +21,7 @@ namespace MalwareMultiScan.Backends.Backends.Abstracts
protected virtual Regex MatchRegex { get; } protected virtual Regex MatchRegex { get; }
protected virtual string BackendPath { get; } protected virtual string BackendPath { get; }
protected virtual bool ParseStdErr { get; } protected virtual bool ParseStdErr { get; }
protected virtual bool ThrowOnNonZeroExitCode { get; } = true;
protected virtual string GetBackendArguments(string path) protected virtual string GetBackendArguments(string path)
{ {
@ -55,12 +56,15 @@ namespace MalwareMultiScan.Backends.Backends.Abstracts
process.WaitForExit(); process.WaitForExit();
_logger.LogInformation($"Process has exited with code {process.ExitCode}"); _logger.LogInformation($"Process has exited with code {process.ExitCode}");
var standardOutput = await process.StandardOutput.ReadToEndAsync(); var standardOutput = await process.StandardOutput.ReadToEndAsync();
var standardError = await process.StandardError.ReadToEndAsync(); var standardError = await process.StandardError.ReadToEndAsync();
_logger.LogDebug($"Process standard output: {standardOutput}"); _logger.LogDebug($"Process standard output: {standardOutput}");
_logger.LogDebug($"Process standard error: {standardError}"); _logger.LogDebug($"Process standard error: {standardError}");
if (ThrowOnNonZeroExitCode && process.ExitCode != 0)
throw new ApplicationException($"Process has terminated with an exit code {process.ExitCode}");
return MatchRegex return MatchRegex
.Matches(ParseStdErr ? standardError : standardOutput) .Matches(ParseStdErr ? standardError : standardOutput)