mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Print commands on build failure (#2004)
This commit is contained in:
@@ -31,25 +31,20 @@ public class RunOptions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public struct ExitStatus
|
public struct ExitStatus
|
||||||
{
|
{
|
||||||
private int _code;
|
private string _cmd;
|
||||||
|
private string _args;
|
||||||
|
private int _exitCode;
|
||||||
private bool _timeOut;
|
private bool _timeOut;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default constructor when the execution finished.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="code">The exit code</param>
|
|
||||||
public ExitStatus(int code)
|
|
||||||
{
|
|
||||||
this._code = code;
|
|
||||||
this._timeOut = false;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Default constructor when the execution potentially timed out.
|
/// Default constructor when the execution potentially timed out.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="code">The exit code</param>
|
/// <param name="process">The process this status is for</param>
|
||||||
/// <param name="timeOut">True if the execution timed out</param>
|
/// <param name="timeOut">True if the execution timed out</param>
|
||||||
public ExitStatus(int code, bool timeOut)
|
public ExitStatus(string cmd, string args, int exitCode, bool timeOut = false)
|
||||||
{
|
{
|
||||||
this._code = code;
|
this._cmd = cmd;
|
||||||
|
this._args = args;
|
||||||
|
this._exitCode = exitCode;
|
||||||
this._timeOut = timeOut;
|
this._timeOut = timeOut;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -63,7 +58,7 @@ public struct ExitStatus
|
|||||||
/// <returns>The exit code</returns>
|
/// <returns>The exit code</returns>
|
||||||
public static implicit operator int(ExitStatus exitStatus)
|
public static implicit operator int(ExitStatus exitStatus)
|
||||||
{
|
{
|
||||||
return exitStatus._code;
|
return exitStatus._exitCode;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Trigger Exception for non-zero exit code.
|
/// Trigger Exception for non-zero exit code.
|
||||||
@@ -72,9 +67,9 @@ public struct ExitStatus
|
|||||||
/// <returns>The exit status for further queries</returns>
|
/// <returns>The exit status for further queries</returns>
|
||||||
public ExitStatus ExceptionOnError(string errorMessage)
|
public ExitStatus ExceptionOnError(string errorMessage)
|
||||||
{
|
{
|
||||||
if (this._code != 0)
|
if (this._exitCode != 0)
|
||||||
{
|
{
|
||||||
throw new Exception(errorMessage);
|
throw new Exception(errorMessage + $"\nCommand: {this._cmd} {this._args}");
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -150,19 +145,19 @@ ExitStatus Run(string exec, string args, RunOptions runOptions)
|
|||||||
if (runOptions.TimeOut == 0)
|
if (runOptions.TimeOut == 0)
|
||||||
{
|
{
|
||||||
process.WaitForExit();
|
process.WaitForExit();
|
||||||
return new ExitStatus(process.ExitCode);
|
return new ExitStatus(exec, args, process.ExitCode);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool finished = process.WaitForExit(runOptions.TimeOut);
|
bool finished = process.WaitForExit(runOptions.TimeOut);
|
||||||
if (finished)
|
if (finished)
|
||||||
{
|
{
|
||||||
return new ExitStatus(process.ExitCode);
|
return new ExitStatus(exec, args, process.ExitCode);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
KillProcessTree(process);
|
KillProcessTree(process);
|
||||||
return new ExitStatus(0, true);
|
return new ExitStatus(exec, args, 0, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,25 +172,12 @@ ExitStatus Run(string exec, string args, RunOptions runOptions)
|
|||||||
ExitStatus RunRestore(string exec, string args, string workingDirectory)
|
ExitStatus RunRestore(string exec, string args, string workingDirectory)
|
||||||
{
|
{
|
||||||
Information("Restoring packages....");
|
Information("Restoring packages....");
|
||||||
var p = StartAndReturnProcess(exec,
|
var exitStatus = Run(exec, args, new RunOptions {
|
||||||
new ProcessSettings
|
WorkingDirectory = workingDirectory
|
||||||
{
|
}).ExceptionOnError($"Error restoring packages.");
|
||||||
Arguments = args,
|
|
||||||
RedirectStandardOutput = true,
|
|
||||||
WorkingDirectory = workingDirectory
|
|
||||||
});
|
|
||||||
p.WaitForExit();
|
|
||||||
var exitCode = p.GetExitCode();
|
|
||||||
|
|
||||||
if (exitCode == 0)
|
Information("Package restore successful!");
|
||||||
{
|
return exitStatus;
|
||||||
Information("Package restore successful!");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Error(string.Join("\n", p.GetStandardOutput()));
|
|
||||||
}
|
|
||||||
return new ExitStatus(exitCode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user