aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2021-12-02 13:47:10 -0800
committerRob Mensching <rob@firegiant.com>2021-12-03 07:48:37 -0800
commit6bbe61062a3f3b22ddfe3501f9be688a74559694 (patch)
tree5df77acb9778322c62f7b125d98414b2ee6276a4 /src
parentb8024608744dc59f1dfd61c402938bcb6b4f7699 (diff)
downloadwix-6bbe61062a3f3b22ddfe3501f9be688a74559694.tar.gz
wix-6bbe61062a3f3b22ddfe3501f9be688a74559694.tar.bz2
wix-6bbe61062a3f3b22ddfe3501f9be688a74559694.zip
Enhance error reporting when running wixnative.exe
Diffstat (limited to 'src')
-rw-r--r--src/wix/WixToolset.Core.Native/WixNativeException.cs38
-rw-r--r--src/wix/WixToolset.Core.Native/WixNativeExe.cs11
2 files changed, 45 insertions, 4 deletions
diff --git a/src/wix/WixToolset.Core.Native/WixNativeException.cs b/src/wix/WixToolset.Core.Native/WixNativeException.cs
new file mode 100644
index 00000000..950e973e
--- /dev/null
+++ b/src/wix/WixToolset.Core.Native/WixNativeException.cs
@@ -0,0 +1,38 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolset.Core.Native
4{
5 using System;
6 using System.Collections.Generic;
7 using System.ComponentModel;
8 using System.Runtime.Serialization;
9
10 [Serializable]
11 internal class WixNativeException : Exception
12 {
13 private static readonly string LineSeparator = Environment.NewLine + " ";
14
15 public WixNativeException()
16 {
17 }
18
19 public WixNativeException(string message) : base(message)
20 {
21 }
22
23 public WixNativeException(string message, Exception innerException) : base(message, innerException)
24 {
25 }
26
27 protected WixNativeException(SerializationInfo info, StreamingContext context) : base(info, context)
28 {
29 }
30
31 public static WixNativeException FromOutputLines(int errorCode, IReadOnlyCollection<string> lines)
32 {
33 var exception = new Win32Exception(errorCode);
34 var output = String.Join(LineSeparator, lines);
35 return new WixNativeException($"wixnative.exe failed with error code: {exception.ErrorCode} - {exception.Message} Output:{LineSeparator}{output}", exception);
36 }
37 }
38}
diff --git a/src/wix/WixToolset.Core.Native/WixNativeExe.cs b/src/wix/WixToolset.Core.Native/WixNativeExe.cs
index fb41b2f2..6e8d64ca 100644
--- a/src/wix/WixToolset.Core.Native/WixNativeExe.cs
+++ b/src/wix/WixToolset.Core.Native/WixNativeExe.cs
@@ -39,17 +39,20 @@ namespace WixToolset.Core.Native
39 { 39 {
40 RedirectStandardInput = true, 40 RedirectStandardInput = true,
41 RedirectStandardOutput = true, 41 RedirectStandardOutput = true,
42 RedirectStandardError = true,
42 CreateNoWindow = true, 43 CreateNoWindow = true,
43 ErrorDialog = false, 44 ErrorDialog = false,
44 UseShellExecute = false 45 UseShellExecute = false
45 }; 46 };
46 47
47 var stdoutLines = new List<string>(); 48 var outputLines = new List<string>();
48 49
49 using (var process = Process.Start(wixNativeInfo)) 50 using (var process = Process.Start(wixNativeInfo))
50 { 51 {
51 process.OutputDataReceived += (s, a) => stdoutLines.Add(a.Data); 52 process.OutputDataReceived += (s, a) => outputLines.Add(a.Data);
53 process.ErrorDataReceived += (s, a) => outputLines.Add(a.Data);
52 process.BeginOutputReadLine(); 54 process.BeginOutputReadLine();
55 process.BeginErrorReadLine();
53 56
54 if (this.stdinLines.Count > 0) 57 if (this.stdinLines.Count > 0)
55 { 58 {
@@ -69,11 +72,11 @@ namespace WixToolset.Core.Native
69 72
70 if (process.ExitCode != 0) 73 if (process.ExitCode != 0)
71 { 74 {
72 throw new Win32Exception(process.ExitCode); 75 throw WixNativeException.FromOutputLines(process.ExitCode, outputLines);
73 } 76 }
74 } 77 }
75 78
76 return stdoutLines; 79 return outputLines;
77 } 80 }
78 81
79 private static void EnsurePathToWixNativeExeSet() 82 private static void EnsurePathToWixNativeExeSet()