Skip to content

Commit

Permalink
capture exception for iinvalid command
Browse files Browse the repository at this point in the history
  • Loading branch information
jgsogo committed Jul 16, 2019
1 parent 156c49d commit a7ddc15
Showing 1 changed file with 43 additions and 31 deletions.
74 changes: 43 additions & 31 deletions Conan.VisualStudio/Services/ConanService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,41 +147,53 @@ private async Task InstallDependenciesAsync(ConanRunner conan, ConanProject proj
Logger.Log(message);
await logStream.WriteLineAsync(message);

using (Process exeProcess = Process.Start(process))
try
{
int exitCode = await exeProcess.WaitForExitAsync();

var tokenSource = new CancellationTokenSource();
var token = tokenSource.Token;

Task outputReader = Task.Factory.StartNew(AppendLinesFunc,
Tuple.Create(logStream, exeProcess.StandardOutput),
token, TaskCreationOptions.None, TaskScheduler.Default);
Task errorReader = Task.Factory.StartNew(AppendLinesFunc,
Tuple.Create(logStream, exeProcess.StandardError),
token, TaskCreationOptions.None, TaskScheduler.Default);

Task.WaitAll(outputReader, errorReader);

if (exitCode != 0) {
message = $"Conan has returned exit code '{exitCode}' " +
$"while processing configuration '{configuration}'. " +
$"Please check file '{logFilePath}' for details.";

Logger.Log(message);
await logStream.WriteLineAsync(message);
_errorListService.WriteError(message, logFilePath);
return;
}
else
using (Process exeProcess = Process.Start(process))
{
message = $"[Conan.VisualStudio] Conan has succsessfully " +
$"installed configuration '{configuration}'";
Logger.Log(message);
await logStream.WriteLineAsync(message);
_errorListService.WriteMessage(message);
int exitCode = await exeProcess.WaitForExitAsync();

string output = await exeProcess.StandardOutput.ReadToEndAsync();
string error = await exeProcess.StandardError.ReadToEndAsync();

if (output.Length > 0)
{
Logger.Log(output);
await logStream.WriteLineAsync(output);
}

if (error.Length > 0)
{
Logger.Log(error);
await logStream.WriteLineAsync(error);
}

if (exitCode != 0)
{
message = $"Conan has returned exit code '{exitCode}' " +
$"while processing configuration '{configuration}'. " +
$"Please check file '{logFilePath}' for details.";

Logger.Log(message);
await logStream.WriteLineAsync(message);
_errorListService.WriteError(message, logFilePath);
return;
}
else
{
message = $"[Conan.VisualStudio] Conan has succsessfully " +
$"installed configuration '{configuration}'";
Logger.Log(message);
await logStream.WriteLineAsync(message);
_errorListService.WriteMessage(message);
}
}
}
catch(System.ComponentModel.Win32Exception)
{
message = $"Error running '{process.FileName}'. Is it a valid path to conan.exe?";
_errorListService.WriteError(message);
}
}
}
}
Expand Down

0 comments on commit a7ddc15

Please sign in to comment.