From 585086c7f2a1f5f41e9b4d948e968906ef890ed8 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 8 Feb 2022 12:13:40 -0800 Subject: Prefer logging messages to throwing out of the Validator Exceptions could cross process boundaries given the callback nature of validation so try to write error messages as soon as errors happen instead of throwing. --- .../IWindowsInstallerValidatorCallback.cs | 13 +++++--- .../WindowsInstallerValidator.cs | 37 ++++++++++++++-------- .../Validate/ValidateDatabaseCommand.cs | 14 ++++---- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/wix/WixToolset.Core.Native/IWindowsInstallerValidatorCallback.cs b/src/wix/WixToolset.Core.Native/IWindowsInstallerValidatorCallback.cs index f4aff134..0d398acb 100644 --- a/src/wix/WixToolset.Core.Native/IWindowsInstallerValidatorCallback.cs +++ b/src/wix/WixToolset.Core.Native/IWindowsInstallerValidatorCallback.cs @@ -2,6 +2,8 @@ namespace WixToolset.Core.Native { + using WixToolset.Data; + /// /// Callbacks during validation. /// @@ -12,16 +14,17 @@ namespace WixToolset.Core.Native /// bool EncounteredError { get; } - /// - /// Validation blocked by another Windows Installer operation. - /// - void ValidationBlocked(); - /// /// Validation message from an ICE. /// /// The validation message. /// True if validation should continue; otherwise cancel the validation. bool ValidationMessage(ValidationMessage message); + + /// + /// Normal message encountered while preparing for ICE validation. + /// + /// The message to write. + void WriteMessage(Message message); } } diff --git a/src/wix/WixToolset.Core.Native/WindowsInstallerValidator.cs b/src/wix/WixToolset.Core.Native/WindowsInstallerValidator.cs index 39242577..4c1a3952 100644 --- a/src/wix/WixToolset.Core.Native/WindowsInstallerValidator.cs +++ b/src/wix/WixToolset.Core.Native/WindowsInstallerValidator.cs @@ -65,7 +65,7 @@ namespace WixToolset.Core.Native { if (!mutex.WaitOne(0)) { - this.Callback.ValidationBlocked(); + this.Callback.WriteMessage(VerboseMessages.ValidationSerialized()); mutex.WaitOne(); } } @@ -124,7 +124,8 @@ namespace WixToolset.Core.Native if (!findCubeFile.Found) { - throw new WixException(ErrorMessages.CubeFileNotFound(findCubeFile.Path)); + this.Callback.WriteMessage(ErrorMessages.CubeFileNotFound(findCubeFile.Path)); + continue; } try @@ -145,10 +146,12 @@ namespace WixToolset.Core.Native { if (0x6E == e.NativeErrorCode) // ERROR_OPEN_FAILED { - throw new WixException(ErrorMessages.CubeFileNotFound(findCubeFile.Path)); + this.Callback.WriteMessage(ErrorMessages.CubeFileNotFound(findCubeFile.Path)); + } + else + { + this.Callback.WriteMessage(ErrorMessages.UnexpectedException($"Unexpected exception while merging CUB: {findCubeFile.Path}, detail: {e.Message}", e.GetType().ToString(), e.StackTrace)); } - - throw; } } @@ -212,7 +215,7 @@ namespace WixToolset.Core.Native { if (!this.Callback.EncounteredError) { - throw e; + this.Callback.WriteMessage(ErrorMessages.UnexpectedException($"Unexpected exception while executing ICE: {action}, detail: {e.Message}", e.GetType().ToString(), e.StackTrace)); } } @@ -236,29 +239,29 @@ namespace WixToolset.Core.Native // this would be the temporary copy and there would be no final output becasue // this error occured; and during standalone validation they should know the path // passed in. - throw new WixException(ErrorMessages.ValidationFailedToOpenDatabase()); + this.Callback.WriteMessage(ErrorMessages.ValidationFailedToOpenDatabase()); } else if (0x64D == e.NativeErrorCode) { - throw new WixException(ErrorMessages.ValidationFailedDueToLowMsiEngine()); + this.Callback.WriteMessage(ErrorMessages.ValidationFailedDueToLowMsiEngine()); } else if (0x654 == e.NativeErrorCode) { - throw new WixException(ErrorMessages.ValidationFailedDueToInvalidPackage()); + this.Callback.WriteMessage(ErrorMessages.ValidationFailedDueToInvalidPackage()); } else if (0x658 == e.NativeErrorCode) { - throw new WixException(ErrorMessages.ValidationFailedDueToMultilanguageMergeModule()); + this.Callback.WriteMessage(ErrorMessages.ValidationFailedDueToMultilanguageMergeModule()); } else if (0x659 == e.NativeErrorCode) { - throw new WixException(WarningMessages.ValidationFailedDueToSystemPolicy()); + this.Callback.WriteMessage(WarningMessages.ValidationFailedDueToSystemPolicy()); } else { var msg = String.IsNullOrEmpty(this.CurrentIce) ? e.Message : $"Action - '{this.CurrentIce}' {e.Message}"; - throw new WixException(ErrorMessages.Win32Exception(e.NativeErrorCode, msg)); + this.Callback.WriteMessage(ErrorMessages.Win32Exception(e.NativeErrorCode, msg)); } } } @@ -294,9 +297,15 @@ namespace WixToolset.Core.Native continueValidation = this.Callback.ValidationMessage(parsedMessage); } - catch + catch (WixException e) + { + this.Callback.WriteMessage(e.Error); + return -1; + } + catch (Exception e) { - return - 1; + this.Callback.WriteMessage(ErrorMessages.UnexpectedException($"Unexpected exception while executing action: {this.CurrentIce}, detail: {e.Message}", e.GetType().ToString(), e.StackTrace)); + return -1; } } diff --git a/src/wix/WixToolset.Core.WindowsInstaller/Validate/ValidateDatabaseCommand.cs b/src/wix/WixToolset.Core.WindowsInstaller/Validate/ValidateDatabaseCommand.cs index fe2fd2c2..fa01a119 100644 --- a/src/wix/WixToolset.Core.WindowsInstaller/Validate/ValidateDatabaseCommand.cs +++ b/src/wix/WixToolset.Core.WindowsInstaller/Validate/ValidateDatabaseCommand.cs @@ -117,20 +117,20 @@ namespace WixToolset.Core.WindowsInstaller.Validate } /// - /// Validation blocked by other installation operation for . + /// Validation message implementation for . /// - public void ValidationBlocked() + public bool ValidationMessage(ValidationMessage message) { - this.Messaging.Write(VerboseMessages.ValidationSerialized()); + this.LogValidationMessage(message); + return true; } /// - /// Validation message implementation for . + /// Normal message encountered while preparing for ICE validation for . /// - public bool ValidationMessage(ValidationMessage message) + public void WriteMessage(Message message) { - this.LogValidationMessage(message); - return true; + this.Messaging.Write(message); } /// -- cgit v1.2.3-55-g6feb