@joebigelow / wix / commits / 42b570e3

Throw WixException for internal errors and Messaging for user errors

Rob Mensching committed Mar 23, 2021 at 15:54 UTC 42b570e34f9cfadbf6f6135cd6b55630c13538be
3 files changed +15 -14
src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs
+2 -2
@@ -581,7 +581,7 @@ namespace WixToolset.Core.Burn
581
582 if (0 == symbols.Count)
583 {
584 - this.Messaging.Write(ErrorMessages.MissingBundleInformation(nameof(T)));
584 + throw new WixException(ErrorMessages.MissingBundleInformation(nameof(T)));
585 }
586
587 return symbols;
@@ -593,7 +593,7 @@ namespace WixToolset.Core.Burn
593
594 if (1 != symbols.Count)
595 {
596 - this.Messaging.Write(ErrorMessages.MissingBundleInformation(nameof(T)));
596 + throw new WixException(ErrorMessages.MissingBundleInformation(nameof(T)));
597 }
598
599 return symbols[0];
src/WixToolset.Core.WindowsInstaller/Bind/SequenceActionsCommand.cs
+5 -5
@@ -67,7 +67,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
67 }
68 else // not a supported unscheduled action.
69 {
70 - throw new InvalidOperationException($"Found an action [{actionSymbol.Id.Id}] at [{actionSymbol.SourceLineNumbers}] with no Sequence, Before, or After column set.");
70 + throw new WixException($"Found action '{actionSymbol.Id.Id}' at {actionSymbol.SourceLineNumbers}' with no Sequence, Before, or After column set. The compiler should have prevented this.");
71 }
72 }
73
@@ -580,7 +580,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
580 }
581 else if (actionSymbol.Before == null)
582 {
583 - throw new InvalidOperationException($"Found an action [{actionSymbol.Id.Id}] at [{actionSymbol.SourceLineNumbers}] with no Sequence, Before, or After column set.");
583 + throw new WixException($"Found action '{actionSymbol.Id.Id}' at {actionSymbol.SourceLineNumbers}' with no Sequence, Before, or After column set. The compiler should have prevented this.");
584 }
585
586 var parentActionName = (after ? actionSymbol.After : actionSymbol.Before);
@@ -598,7 +598,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
598 }
599 else
600 {
601 - throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, "Found an action with a non-existent {0} action: {1}.", (after ? "After" : "Before"), parentActionName));
601 + throw new WixException($"Found action {actionSymbol.Id.Id} with a non-existent {(after ? "After" : "Before")} action '{parentActionName}'. The linker should have prevented this.");
602 }
603 }
604
@@ -639,11 +639,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind
639 }
640 else if (existingInitialActionSymbol == actionSymbol)
641 {
642 - throw new WixException(ErrorMessages.ActionCircularDependency(currentActionSymbol.SourceLineNumbers, currentActionSymbol.SequenceTable.ToString(), currentActionSymbol.Action, previousActionSymbol.Action));
642 + this.Messaging.Write(ErrorMessages.ActionCircularDependency(currentActionSymbol.SourceLineNumbers, currentActionSymbol.SequenceTable.ToString(), currentActionSymbol.Action, previousActionSymbol.Action));
643 }
644
645 parentActionSymbol = this.GetParentActionSymbol(currentActionSymbol, requiredActionSymbols);
646 - } while (null != parentActionSymbol);
646 + } while (null != parentActionSymbol && !this.Messaging.EncounteredError);
647 }
648
649 /// <summary>
src/test/WixToolsetTest.CoreIntegration/CustomActionFixture.cs
+8 -7
@@ -6,7 +6,6 @@ namespace WixToolsetTest.CoreIntegration
6 using System.Linq;
7 using WixBuildTools.TestSupport;
8 using WixToolset.Core.TestPackage;
9 - using WixToolset.Data;
9 using Xunit;
10
11 public class CustomActionFixture
@@ -22,7 +21,7 @@ namespace WixToolsetTest.CoreIntegration
21 var intermediateFolder = Path.Combine(baseFolder, "obj");
22 var msiPath = Path.Combine(baseFolder, @"bin\test.msi");
23
25 - var exception = Assert.Throws<WixException>(() => WixRunner.Execute(new[]
24 + var result = WixRunner.Execute(new[]
25 {
26 "build",
27 Path.Combine(folder, "CustomAction", "CustomActionCycle.wxs"),
@@ -31,9 +30,10 @@ namespace WixToolsetTest.CoreIntegration
30 "-bindpath", Path.Combine(folder, "SingleFile", "data"),
31 "-intermediateFolder", intermediateFolder,
32 "-o", msiPath
34 - }));
33 + });
34
36 - Assert.Equal("The InstallExecuteSequence table contains an action 'Action1' that is scheduled to come before or after action 'Action3', which is also scheduled to come before or after action 'Action1'. Please remove this circular dependency by changing the Before or After attribute for one of the actions.", exception.Message);
35 + Assert.Equal(176, result.ExitCode);
36 + Assert.Equal("The InstallExecuteSequence table contains an action 'Action1' that is scheduled to come before or after action 'Action3', which is also scheduled to come before or after action 'Action1'. Please remove this circular dependency by changing the Before or After attribute for one of the actions.", result.Messages[0].ToString());
37 }
38 }
39
@@ -48,7 +48,7 @@ namespace WixToolsetTest.CoreIntegration
48 var intermediateFolder = Path.Combine(baseFolder, "obj");
49 var msiPath = Path.Combine(baseFolder, @"bin\test.msi");
50
51 - var exception = Assert.Throws<WixException>(() => WixRunner.Execute(new[]
51 + var result = WixRunner.Execute(new[]
52 {
53 "build",
54 Path.Combine(folder, "CustomAction", "CustomActionCycleWithTail.wxs"),
@@ -57,9 +57,10 @@ namespace WixToolsetTest.CoreIntegration
57 "-bindpath", Path.Combine(folder, "SingleFile", "data"),
58 "-intermediateFolder", intermediateFolder,
59 "-o", msiPath
60 - }));
60 + });
61
62 - Assert.Equal("The InstallExecuteSequence table contains an action 'Action2' that is scheduled to come before or after action 'Action4', which is also scheduled to come before or after action 'Action2'. Please remove this circular dependency by changing the Before or After attribute for one of the actions.", exception.Message);
62 + Assert.Equal(176, result.ExitCode);
63 + Assert.Equal("The InstallExecuteSequence table contains an action 'Action2' that is scheduled to come before or after action 'Action4', which is also scheduled to come before or after action 'Action2'. Please remove this circular dependency by changing the Before or After attribute for one of the actions.", result.Messages[0].ToString());
64 }
65 }
66