mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
C#: Gracefully handle non-zero exitcodes for dotnet --info.
This commit is contained in:
@@ -57,15 +57,21 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
return startInfo;
|
||||
}
|
||||
|
||||
private bool RunCommandAux(string args, string? workingDirectory, out IList<string> output, bool silent)
|
||||
private int RunCommandExitCodeAux(string args, string? workingDirectory, out IList<string> output, out string dirLog, bool silent)
|
||||
{
|
||||
var dirLog = string.IsNullOrWhiteSpace(workingDirectory) ? "" : $" in {workingDirectory}";
|
||||
dirLog = string.IsNullOrWhiteSpace(workingDirectory) ? "" : $" in {workingDirectory}";
|
||||
var pi = MakeDotnetStartInfo(args, workingDirectory);
|
||||
var threadId = Environment.CurrentManagedThreadId;
|
||||
void onOut(string s) => logger.Log(silent ? Severity.Debug : Severity.Info, s, threadId);
|
||||
void onError(string s) => logger.LogError(s, threadId);
|
||||
logger.LogInfo($"Running '{Exec} {args}'{dirLog}");
|
||||
var exitCode = pi.ReadOutput(out output, onOut, onError);
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
private bool RunCommandAux(string args, string? workingDirectory, out IList<string> output, bool silent)
|
||||
{
|
||||
var exitCode = RunCommandExitCodeAux(args, workingDirectory, out output, out var dirLog, silent);
|
||||
if (exitCode != 0)
|
||||
{
|
||||
logger.LogError($"Command '{Exec} {args}'{dirLog} failed with exit code {exitCode}");
|
||||
@@ -77,6 +83,9 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
public bool RunCommand(string args, bool silent = true) =>
|
||||
RunCommandAux(args, null, out _, silent);
|
||||
|
||||
public int RunCommandExitCode(string args, bool silent = true) =>
|
||||
RunCommandExitCodeAux(args, null, out _, out _, silent);
|
||||
|
||||
public bool RunCommand(string args, out IList<string> output, bool silent = true) =>
|
||||
RunCommandAux(args, null, out output, silent);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user