From a7ddc15bc52eea44915ff181df29a9fd322abdc8 Mon Sep 17 00:00:00 2001 From: "Javier G. Sogo" Date: Fri, 28 Jun 2019 17:07:10 +0200 Subject: [PATCH] capture exception for iinvalid command --- Conan.VisualStudio/Services/ConanService.cs | 74 ++++++++++++--------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/Conan.VisualStudio/Services/ConanService.cs b/Conan.VisualStudio/Services/ConanService.cs index 9947f34d..1b474459 100644 --- a/Conan.VisualStudio/Services/ConanService.cs +++ b/Conan.VisualStudio/Services/ConanService.cs @@ -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); + } } } }