From 42b570e34f9cfadbf6f6135cd6b55630c13538be Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 23 Mar 2021 15:54:20 -0700 Subject: Throw WixException for internal errors and Messaging for user errors --- src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs | 4 ++-- .../Bind/SequenceActionsCommand.cs | 10 +++++----- .../WixToolsetTest.CoreIntegration/CustomActionFixture.cs | 15 ++++++++------- 3 files changed, 15 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs b/src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs index 1cc9987e..4e07d598 100644 --- a/src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs +++ b/src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs @@ -581,7 +581,7 @@ namespace WixToolset.Core.Burn if (0 == symbols.Count) { - this.Messaging.Write(ErrorMessages.MissingBundleInformation(nameof(T))); + throw new WixException(ErrorMessages.MissingBundleInformation(nameof(T))); } return symbols; @@ -593,7 +593,7 @@ namespace WixToolset.Core.Burn if (1 != symbols.Count) { - this.Messaging.Write(ErrorMessages.MissingBundleInformation(nameof(T))); + throw new WixException(ErrorMessages.MissingBundleInformation(nameof(T))); } return symbols[0]; diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/SequenceActionsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/SequenceActionsCommand.cs index 7d75d74c..5e72ec5c 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/SequenceActionsCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/SequenceActionsCommand.cs @@ -67,7 +67,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind } else // not a supported unscheduled action. { - throw new InvalidOperationException($"Found an action [{actionSymbol.Id.Id}] at [{actionSymbol.SourceLineNumbers}] with no Sequence, Before, or After column set."); + 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."); } } @@ -580,7 +580,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind } else if (actionSymbol.Before == null) { - throw new InvalidOperationException($"Found an action [{actionSymbol.Id.Id}] at [{actionSymbol.SourceLineNumbers}] with no Sequence, Before, or After column set."); + 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."); } var parentActionName = (after ? actionSymbol.After : actionSymbol.Before); @@ -598,7 +598,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind } else { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, "Found an action with a non-existent {0} action: {1}.", (after ? "After" : "Before"), parentActionName)); + throw new WixException($"Found action {actionSymbol.Id.Id} with a non-existent {(after ? "After" : "Before")} action '{parentActionName}'. The linker should have prevented this."); } } @@ -639,11 +639,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind } else if (existingInitialActionSymbol == actionSymbol) { - throw new WixException(ErrorMessages.ActionCircularDependency(currentActionSymbol.SourceLineNumbers, currentActionSymbol.SequenceTable.ToString(), currentActionSymbol.Action, previousActionSymbol.Action)); + this.Messaging.Write(ErrorMessages.ActionCircularDependency(currentActionSymbol.SourceLineNumbers, currentActionSymbol.SequenceTable.ToString(), currentActionSymbol.Action, previousActionSymbol.Action)); } parentActionSymbol = this.GetParentActionSymbol(currentActionSymbol, requiredActionSymbols); - } while (null != parentActionSymbol); + } while (null != parentActionSymbol && !this.Messaging.EncounteredError); } /// diff --git a/src/test/WixToolsetTest.CoreIntegration/CustomActionFixture.cs b/src/test/WixToolsetTest.CoreIntegration/CustomActionFixture.cs index 7980ea61..636b86a6 100644 --- a/src/test/WixToolsetTest.CoreIntegration/CustomActionFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/CustomActionFixture.cs @@ -6,7 +6,6 @@ namespace WixToolsetTest.CoreIntegration using System.Linq; using WixBuildTools.TestSupport; using WixToolset.Core.TestPackage; - using WixToolset.Data; using Xunit; public class CustomActionFixture @@ -22,7 +21,7 @@ namespace WixToolsetTest.CoreIntegration var intermediateFolder = Path.Combine(baseFolder, "obj"); var msiPath = Path.Combine(baseFolder, @"bin\test.msi"); - var exception = Assert.Throws(() => WixRunner.Execute(new[] + var result = WixRunner.Execute(new[] { "build", Path.Combine(folder, "CustomAction", "CustomActionCycle.wxs"), @@ -31,9 +30,10 @@ namespace WixToolsetTest.CoreIntegration "-bindpath", Path.Combine(folder, "SingleFile", "data"), "-intermediateFolder", intermediateFolder, "-o", msiPath - })); + }); - 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); + Assert.Equal(176, result.ExitCode); + 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()); } } @@ -48,7 +48,7 @@ namespace WixToolsetTest.CoreIntegration var intermediateFolder = Path.Combine(baseFolder, "obj"); var msiPath = Path.Combine(baseFolder, @"bin\test.msi"); - var exception = Assert.Throws(() => WixRunner.Execute(new[] + var result = WixRunner.Execute(new[] { "build", Path.Combine(folder, "CustomAction", "CustomActionCycleWithTail.wxs"), @@ -57,9 +57,10 @@ namespace WixToolsetTest.CoreIntegration "-bindpath", Path.Combine(folder, "SingleFile", "data"), "-intermediateFolder", intermediateFolder, "-o", msiPath - })); + }); - 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); + Assert.Equal(176, result.ExitCode); + 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()); } } -- cgit v1.2.3-55-g6feb