Throw WixException for internal errors and Messaging for user errors

This commit is contained in:
Rob Mensching 2021-03-23 15:54:20 -07:00
Родитель 26442d4177
Коммит 42b570e34f
3 изменённых файлов: 15 добавлений и 14 удалений

Просмотреть файл

@ -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];

Просмотреть файл

@ -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);
}
/// <summary>

Просмотреть файл

@ -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<WixException>(() => 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<WixException>(() => 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());
}
}