From c6da3f6d1c9b571d8f58745560332c3e0531a5c5 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 27 Dec 2018 11:07:13 -0800 Subject: Catch unhandled exceptions at the top to provide useful debug info Fixes wixtoolset/issues#5884 --- src/WixToolset.BuildTasks/DoIt.cs | 22 ++++++++------- .../WixToolset.BuildTasks.csproj | 1 - .../WixToolset.Tools.Core.csproj | 2 -- src/wix/Program.cs | 31 +++++++++++++++++----- src/wix/wix.csproj | 1 - 5 files changed, 37 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/WixToolset.BuildTasks/DoIt.cs b/src/WixToolset.BuildTasks/DoIt.cs index aeeb428b..07bf05e5 100644 --- a/src/WixToolset.BuildTasks/DoIt.cs +++ b/src/WixToolset.BuildTasks/DoIt.cs @@ -4,8 +4,6 @@ namespace WixToolset.BuildTasks { using System; using System.Collections.Generic; - using System.Linq; - using System.Reflection; using System.Runtime.InteropServices; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -111,9 +109,17 @@ namespace WixToolset.BuildTasks public override bool Execute() { + var serviceProvider = new WixToolsetServiceProvider(); + + var listener = new MsbuildMessageListener(this.Log, "WIX", this.BuildEngine.ProjectFileOfTaskNode); + try { - this.ExecuteCore(); + this.ExecuteCore(serviceProvider, listener); + } + catch (WixException e) + { + listener.Write(e.Error); } catch (Exception e) { @@ -128,10 +134,8 @@ namespace WixToolset.BuildTasks return !this.Log.HasLoggedErrors; } - private void ExecuteCore() + private void ExecuteCore(IServiceProvider serviceProvider, IMessageListener listener) { - var listener = new MsbuildMessageListener(this.Log, "WIX", this.BuildEngine.ProjectFileOfTaskNode); - var commandLineBuilder = new WixCommandLineBuilder(); commandLineBuilder.AppendTextUnquoted("build"); @@ -164,8 +168,6 @@ namespace WixToolset.BuildTasks this.Log.LogMessage(MessageImportance.Normal, "wix.exe " + commandLineString); - var serviceProvider = new WixToolsetServiceProvider(); - var messaging = serviceProvider.GetService(); messaging.SetListener(listener); @@ -194,9 +196,9 @@ namespace WixToolset.BuildTasks { extensionManager.Load(extension); } - catch (ReflectionTypeLoadException e) + catch (WixException e) { - messaging.Write(ErrorMessages.InvalidExtension(extension, String.Join(Environment.NewLine, e.LoaderExceptions.Select(le => le.ToString())))); + messaging.Write(e.Error); } } diff --git a/src/WixToolset.BuildTasks/WixToolset.BuildTasks.csproj b/src/WixToolset.BuildTasks/WixToolset.BuildTasks.csproj index 10a3f057..5020f891 100644 --- a/src/WixToolset.BuildTasks/WixToolset.BuildTasks.csproj +++ b/src/WixToolset.BuildTasks/WixToolset.BuildTasks.csproj @@ -32,7 +32,6 @@ - diff --git a/src/WixToolset.Tools.Core/WixToolset.Tools.Core.csproj b/src/WixToolset.Tools.Core/WixToolset.Tools.Core.csproj index 996258cc..92111c61 100644 --- a/src/WixToolset.Tools.Core/WixToolset.Tools.Core.csproj +++ b/src/WixToolset.Tools.Core/WixToolset.Tools.Core.csproj @@ -11,8 +11,6 @@ - - diff --git a/src/wix/Program.cs b/src/wix/Program.cs index 276eba53..a3251f84 100644 --- a/src/wix/Program.cs +++ b/src/wix/Program.cs @@ -3,8 +3,7 @@ namespace WixToolset.Tools { using System; - using System.Linq; - using System.Reflection; + using System.Runtime.InteropServices; using WixToolset.Core; using WixToolset.Data; using WixToolset.Extensibility; @@ -29,8 +28,28 @@ namespace WixToolset.Tools var listener = new ConsoleMessageListener("WIX", "wix.exe"); - var program = new Program(); - return program.Run(serviceProvider, listener, args); + try + { + var program = new Program(); + return program.Run(serviceProvider, listener, args); + } + catch (WixException e) + { + listener.Write(e.Error); + + return e.Error.Id; + } + catch (Exception e) + { + listener.Write(ErrorMessages.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); + + if (e is NullReferenceException || e is SEHException) + { + throw; + } + + return e.HResult; + } } /// @@ -69,9 +88,9 @@ namespace WixToolset.Tools { extensionManager.Load(extension); } - catch (ReflectionTypeLoadException e) + catch (WixException e) { - messaging.Write(ErrorMessages.InvalidExtension(extension, String.Join(Environment.NewLine, e.LoaderExceptions.Select(le => le.ToString())))); + messaging.Write(e.Error); } } diff --git a/src/wix/wix.csproj b/src/wix/wix.csproj index a923c66f..9cb5658f 100644 --- a/src/wix/wix.csproj +++ b/src/wix/wix.csproj @@ -21,7 +21,6 @@ - -- cgit v1.2.3-55-g6feb