diff options
author | Rob Mensching <rob@firegiant.com> | 2022-02-08 12:13:40 -0800 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2022-02-10 20:47:53 -0800 |
commit | 585086c7f2a1f5f41e9b4d948e968906ef890ed8 (patch) | |
tree | b035db13d05bdec275d7b887473fb2d696fb00fc | |
parent | 8da1c3874dfd915def53bb18b5375bf7a15f496d (diff) | |
download | wix-585086c7f2a1f5f41e9b4d948e968906ef890ed8.tar.gz wix-585086c7f2a1f5f41e9b4d948e968906ef890ed8.tar.bz2 wix-585086c7f2a1f5f41e9b4d948e968906ef890ed8.zip |
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.
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 @@ | |||
2 | 2 | ||
3 | namespace WixToolset.Core.Native | 3 | namespace WixToolset.Core.Native |
4 | { | 4 | { |
5 | using WixToolset.Data; | ||
6 | |||
5 | /// <summary> | 7 | /// <summary> |
6 | /// Callbacks during validation. | 8 | /// Callbacks during validation. |
7 | /// </summary> | 9 | /// </summary> |
@@ -13,15 +15,16 @@ namespace WixToolset.Core.Native | |||
13 | bool EncounteredError { get; } | 15 | bool EncounteredError { get; } |
14 | 16 | ||
15 | /// <summary> | 17 | /// <summary> |
16 | /// Validation blocked by another Windows Installer operation. | ||
17 | /// </summary> | ||
18 | void ValidationBlocked(); | ||
19 | |||
20 | /// <summary> | ||
21 | /// Validation message from an ICE. | 18 | /// Validation message from an ICE. |
22 | /// </summary> | 19 | /// </summary> |
23 | /// <param name="message">The validation message.</param> | 20 | /// <param name="message">The validation message.</param> |
24 | /// <returns>True if validation should continue; otherwise cancel the validation.</returns> | 21 | /// <returns>True if validation should continue; otherwise cancel the validation.</returns> |
25 | bool ValidationMessage(ValidationMessage message); | 22 | bool ValidationMessage(ValidationMessage message); |
23 | |||
24 | /// <summary> | ||
25 | /// Normal message encountered while preparing for ICE validation. | ||
26 | /// </summary> | ||
27 | /// <param name="message">The message to write.</param> | ||
28 | void WriteMessage(Message message); | ||
26 | } | 29 | } |
27 | } | 30 | } |
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 | |||
65 | { | 65 | { |
66 | if (!mutex.WaitOne(0)) | 66 | if (!mutex.WaitOne(0)) |
67 | { | 67 | { |
68 | this.Callback.ValidationBlocked(); | 68 | this.Callback.WriteMessage(VerboseMessages.ValidationSerialized()); |
69 | mutex.WaitOne(); | 69 | mutex.WaitOne(); |
70 | } | 70 | } |
71 | } | 71 | } |
@@ -124,7 +124,8 @@ namespace WixToolset.Core.Native | |||
124 | 124 | ||
125 | if (!findCubeFile.Found) | 125 | if (!findCubeFile.Found) |
126 | { | 126 | { |
127 | throw new WixException(ErrorMessages.CubeFileNotFound(findCubeFile.Path)); | 127 | this.Callback.WriteMessage(ErrorMessages.CubeFileNotFound(findCubeFile.Path)); |
128 | continue; | ||
128 | } | 129 | } |
129 | 130 | ||
130 | try | 131 | try |
@@ -145,10 +146,12 @@ namespace WixToolset.Core.Native | |||
145 | { | 146 | { |
146 | if (0x6E == e.NativeErrorCode) // ERROR_OPEN_FAILED | 147 | if (0x6E == e.NativeErrorCode) // ERROR_OPEN_FAILED |
147 | { | 148 | { |
148 | throw new WixException(ErrorMessages.CubeFileNotFound(findCubeFile.Path)); | 149 | this.Callback.WriteMessage(ErrorMessages.CubeFileNotFound(findCubeFile.Path)); |
150 | } | ||
151 | else | ||
152 | { | ||
153 | this.Callback.WriteMessage(ErrorMessages.UnexpectedException($"Unexpected exception while merging CUB: {findCubeFile.Path}, detail: {e.Message}", e.GetType().ToString(), e.StackTrace)); | ||
149 | } | 154 | } |
150 | |||
151 | throw; | ||
152 | } | 155 | } |
153 | } | 156 | } |
154 | 157 | ||
@@ -212,7 +215,7 @@ namespace WixToolset.Core.Native | |||
212 | { | 215 | { |
213 | if (!this.Callback.EncounteredError) | 216 | if (!this.Callback.EncounteredError) |
214 | { | 217 | { |
215 | throw e; | 218 | this.Callback.WriteMessage(ErrorMessages.UnexpectedException($"Unexpected exception while executing ICE: {action}, detail: {e.Message}", e.GetType().ToString(), e.StackTrace)); |
216 | } | 219 | } |
217 | } | 220 | } |
218 | 221 | ||
@@ -236,29 +239,29 @@ namespace WixToolset.Core.Native | |||
236 | // this would be the temporary copy and there would be no final output becasue | 239 | // this would be the temporary copy and there would be no final output becasue |
237 | // this error occured; and during standalone validation they should know the path | 240 | // this error occured; and during standalone validation they should know the path |
238 | // passed in. | 241 | // passed in. |
239 | throw new WixException(ErrorMessages.ValidationFailedToOpenDatabase()); | 242 | this.Callback.WriteMessage(ErrorMessages.ValidationFailedToOpenDatabase()); |
240 | } | 243 | } |
241 | else if (0x64D == e.NativeErrorCode) | 244 | else if (0x64D == e.NativeErrorCode) |
242 | { | 245 | { |
243 | throw new WixException(ErrorMessages.ValidationFailedDueToLowMsiEngine()); | 246 | this.Callback.WriteMessage(ErrorMessages.ValidationFailedDueToLowMsiEngine()); |
244 | } | 247 | } |
245 | else if (0x654 == e.NativeErrorCode) | 248 | else if (0x654 == e.NativeErrorCode) |
246 | { | 249 | { |
247 | throw new WixException(ErrorMessages.ValidationFailedDueToInvalidPackage()); | 250 | this.Callback.WriteMessage(ErrorMessages.ValidationFailedDueToInvalidPackage()); |
248 | } | 251 | } |
249 | else if (0x658 == e.NativeErrorCode) | 252 | else if (0x658 == e.NativeErrorCode) |
250 | { | 253 | { |
251 | throw new WixException(ErrorMessages.ValidationFailedDueToMultilanguageMergeModule()); | 254 | this.Callback.WriteMessage(ErrorMessages.ValidationFailedDueToMultilanguageMergeModule()); |
252 | } | 255 | } |
253 | else if (0x659 == e.NativeErrorCode) | 256 | else if (0x659 == e.NativeErrorCode) |
254 | { | 257 | { |
255 | throw new WixException(WarningMessages.ValidationFailedDueToSystemPolicy()); | 258 | this.Callback.WriteMessage(WarningMessages.ValidationFailedDueToSystemPolicy()); |
256 | } | 259 | } |
257 | else | 260 | else |
258 | { | 261 | { |
259 | var msg = String.IsNullOrEmpty(this.CurrentIce) ? e.Message : $"Action - '{this.CurrentIce}' {e.Message}"; | 262 | var msg = String.IsNullOrEmpty(this.CurrentIce) ? e.Message : $"Action - '{this.CurrentIce}' {e.Message}"; |
260 | 263 | ||
261 | throw new WixException(ErrorMessages.Win32Exception(e.NativeErrorCode, msg)); | 264 | this.Callback.WriteMessage(ErrorMessages.Win32Exception(e.NativeErrorCode, msg)); |
262 | } | 265 | } |
263 | } | 266 | } |
264 | } | 267 | } |
@@ -294,9 +297,15 @@ namespace WixToolset.Core.Native | |||
294 | 297 | ||
295 | continueValidation = this.Callback.ValidationMessage(parsedMessage); | 298 | continueValidation = this.Callback.ValidationMessage(parsedMessage); |
296 | } | 299 | } |
297 | catch | 300 | catch (WixException e) |
301 | { | ||
302 | this.Callback.WriteMessage(e.Error); | ||
303 | return -1; | ||
304 | } | ||
305 | catch (Exception e) | ||
298 | { | 306 | { |
299 | return - 1; | 307 | this.Callback.WriteMessage(ErrorMessages.UnexpectedException($"Unexpected exception while executing action: {this.CurrentIce}, detail: {e.Message}", e.GetType().ToString(), e.StackTrace)); |
308 | return -1; | ||
300 | } | 309 | } |
301 | } | 310 | } |
302 | 311 | ||
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 | |||
117 | } | 117 | } |
118 | 118 | ||
119 | /// <summary> | 119 | /// <summary> |
120 | /// Validation blocked by other installation operation for <see cref="IWindowsInstallerValidatorCallback"/>. | 120 | /// Validation message implementation for <see cref="IWindowsInstallerValidatorCallback"/>. |
121 | /// </summary> | 121 | /// </summary> |
122 | public void ValidationBlocked() | 122 | public bool ValidationMessage(ValidationMessage message) |
123 | { | 123 | { |
124 | this.Messaging.Write(VerboseMessages.ValidationSerialized()); | 124 | this.LogValidationMessage(message); |
125 | return true; | ||
125 | } | 126 | } |
126 | 127 | ||
127 | /// <summary> | 128 | /// <summary> |
128 | /// Validation message implementation for <see cref="IWindowsInstallerValidatorCallback"/>. | 129 | /// Normal message encountered while preparing for ICE validation for <see cref="IWindowsInstallerValidatorCallback"/>. |
129 | /// </summary> | 130 | /// </summary> |
130 | public bool ValidationMessage(ValidationMessage message) | 131 | public void WriteMessage(Message message) |
131 | { | 132 | { |
132 | this.LogValidationMessage(message); | 133 | this.Messaging.Write(message); |
133 | return true; | ||
134 | } | 134 | } |
135 | 135 | ||
136 | /// <summary> | 136 | /// <summary> |