aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2018-12-27 11:07:13 -0800
committerRob Mensching <rob@robmensching.com>2018-12-27 11:14:08 -0800
commitc6da3f6d1c9b571d8f58745560332c3e0531a5c5 (patch)
tree660515bae84a9480e3fa87bbfd635946935d5f49 /src
parentc82991d4af4ce7fa7330e99e18840ecff4f3fabd (diff)
downloadwix-c6da3f6d1c9b571d8f58745560332c3e0531a5c5.tar.gz
wix-c6da3f6d1c9b571d8f58745560332c3e0531a5c5.tar.bz2
wix-c6da3f6d1c9b571d8f58745560332c3e0531a5c5.zip
Catch unhandled exceptions at the top to provide useful debug info
Fixes wixtoolset/issues#5884
Diffstat (limited to 'src')
-rw-r--r--src/WixToolset.BuildTasks/DoIt.cs22
-rw-r--r--src/WixToolset.BuildTasks/WixToolset.BuildTasks.csproj1
-rw-r--r--src/WixToolset.Tools.Core/WixToolset.Tools.Core.csproj2
-rw-r--r--src/wix/Program.cs31
-rw-r--r--src/wix/wix.csproj1
5 files changed, 37 insertions, 20 deletions
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
4{ 4{
5 using System; 5 using System;
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.Linq;
8 using System.Reflection;
9 using System.Runtime.InteropServices; 7 using System.Runtime.InteropServices;
10 using Microsoft.Build.Framework; 8 using Microsoft.Build.Framework;
11 using Microsoft.Build.Utilities; 9 using Microsoft.Build.Utilities;
@@ -111,9 +109,17 @@ namespace WixToolset.BuildTasks
111 109
112 public override bool Execute() 110 public override bool Execute()
113 { 111 {
112 var serviceProvider = new WixToolsetServiceProvider();
113
114 var listener = new MsbuildMessageListener(this.Log, "WIX", this.BuildEngine.ProjectFileOfTaskNode);
115
114 try 116 try
115 { 117 {
116 this.ExecuteCore(); 118 this.ExecuteCore(serviceProvider, listener);
119 }
120 catch (WixException e)
121 {
122 listener.Write(e.Error);
117 } 123 }
118 catch (Exception e) 124 catch (Exception e)
119 { 125 {
@@ -128,10 +134,8 @@ namespace WixToolset.BuildTasks
128 return !this.Log.HasLoggedErrors; 134 return !this.Log.HasLoggedErrors;
129 } 135 }
130 136
131 private void ExecuteCore() 137 private void ExecuteCore(IServiceProvider serviceProvider, IMessageListener listener)
132 { 138 {
133 var listener = new MsbuildMessageListener(this.Log, "WIX", this.BuildEngine.ProjectFileOfTaskNode);
134
135 var commandLineBuilder = new WixCommandLineBuilder(); 139 var commandLineBuilder = new WixCommandLineBuilder();
136 140
137 commandLineBuilder.AppendTextUnquoted("build"); 141 commandLineBuilder.AppendTextUnquoted("build");
@@ -164,8 +168,6 @@ namespace WixToolset.BuildTasks
164 168
165 this.Log.LogMessage(MessageImportance.Normal, "wix.exe " + commandLineString); 169 this.Log.LogMessage(MessageImportance.Normal, "wix.exe " + commandLineString);
166 170
167 var serviceProvider = new WixToolsetServiceProvider();
168
169 var messaging = serviceProvider.GetService<IMessaging>(); 171 var messaging = serviceProvider.GetService<IMessaging>();
170 messaging.SetListener(listener); 172 messaging.SetListener(listener);
171 173
@@ -194,9 +196,9 @@ namespace WixToolset.BuildTasks
194 { 196 {
195 extensionManager.Load(extension); 197 extensionManager.Load(extension);
196 } 198 }
197 catch (ReflectionTypeLoadException e) 199 catch (WixException e)
198 { 200 {
199 messaging.Write(ErrorMessages.InvalidExtension(extension, String.Join(Environment.NewLine, e.LoaderExceptions.Select(le => le.ToString())))); 201 messaging.Write(e.Error);
200 } 202 }
201 } 203 }
202 204
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 @@
32 </ItemGroup> 32 </ItemGroup>
33 33
34 <ItemGroup> 34 <ItemGroup>
35 <PackageReference Include="WixToolset.Core" Version="4.0.*" />
36 <PackageReference Include="WixToolset.Core.Burn" Version="4.0.*" /> 35 <PackageReference Include="WixToolset.Core.Burn" Version="4.0.*" />
37 <PackageReference Include="WixToolset.Core.WindowsInstaller" Version="4.0.*" /> 36 <PackageReference Include="WixToolset.Core.WindowsInstaller" Version="4.0.*" />
38 </ItemGroup> 37 </ItemGroup>
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 @@
11 </PropertyGroup> 11 </PropertyGroup>
12 12
13 <ItemGroup> 13 <ItemGroup>
14 <PackageReference Include="WixToolset.Data" Version="4.0.*" />
15 <PackageReference Include="WixToolset.Extensibility" Version="4.0.*" />
16 <PackageReference Include="WixToolset.Core" Version="4.0.*" /> 14 <PackageReference Include="WixToolset.Core" Version="4.0.*" />
17 </ItemGroup> 15 </ItemGroup>
18 16
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 @@
3namespace WixToolset.Tools 3namespace WixToolset.Tools
4{ 4{
5 using System; 5 using System;
6 using System.Linq; 6 using System.Runtime.InteropServices;
7 using System.Reflection;
8 using WixToolset.Core; 7 using WixToolset.Core;
9 using WixToolset.Data; 8 using WixToolset.Data;
10 using WixToolset.Extensibility; 9 using WixToolset.Extensibility;
@@ -29,8 +28,28 @@ namespace WixToolset.Tools
29 28
30 var listener = new ConsoleMessageListener("WIX", "wix.exe"); 29 var listener = new ConsoleMessageListener("WIX", "wix.exe");
31 30
32 var program = new Program(); 31 try
33 return program.Run(serviceProvider, listener, args); 32 {
33 var program = new Program();
34 return program.Run(serviceProvider, listener, args);
35 }
36 catch (WixException e)
37 {
38 listener.Write(e.Error);
39
40 return e.Error.Id;
41 }
42 catch (Exception e)
43 {
44 listener.Write(ErrorMessages.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace));
45
46 if (e is NullReferenceException || e is SEHException)
47 {
48 throw;
49 }
50
51 return e.HResult;
52 }
34 } 53 }
35 54
36 /// <summary> 55 /// <summary>
@@ -69,9 +88,9 @@ namespace WixToolset.Tools
69 { 88 {
70 extensionManager.Load(extension); 89 extensionManager.Load(extension);
71 } 90 }
72 catch (ReflectionTypeLoadException e) 91 catch (WixException e)
73 { 92 {
74 messaging.Write(ErrorMessages.InvalidExtension(extension, String.Join(Environment.NewLine, e.LoaderExceptions.Select(le => le.ToString())))); 93 messaging.Write(e.Error);
75 } 94 }
76 } 95 }
77 96
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 @@
21 </ItemGroup> 21 </ItemGroup>
22 22
23 <ItemGroup> 23 <ItemGroup>
24 <PackageReference Include="WixToolset.Core" Version="4.0.*" />
25 <PackageReference Include="WixToolset.Core.Burn" Version="4.0.*" /> 24 <PackageReference Include="WixToolset.Core.Burn" Version="4.0.*" />
26 <PackageReference Include="WixToolset.Core.WindowsInstaller" Version="4.0.*" /> 25 <PackageReference Include="WixToolset.Core.WindowsInstaller" Version="4.0.*" />
27 </ItemGroup> 26 </ItemGroup>