diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs index c96effb5b2c..2cd2710766e 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs @@ -822,10 +822,18 @@ private void CurrentDispatcher_UnhandledException(object sender, DispatcherUnhan return; } - // Try to handle the exception so that the host app can continue (in most cases). - // In some cases Dynamo code might still crash after this handler kicks in. In these edge cases - // we might see 2 CER windows (the extra one from the host app) - CER tool might handle this in the future. - e.Handled = true; + if (DynamoModel.IsTestMode) + { + // Do not handle the exception in test mode. + // Let the test host handle it. + } + else + { + // Try to handle the exception so that the host app can continue (in most cases). + // In some cases Dynamo code might still crash after this handler kicks in. In these edge cases + // we might see 2 CER windows (the extra one from the host app) - CER tool might handle this in the future. + e.Handled = true; + } CrashGracefully(e.Exception); } @@ -857,12 +865,6 @@ private void CrashGracefully(Exception ex, bool fatal = false) var crashDetails = new CrashErrorReportArgs(ex); DynamoConsoleLogger.OnLogErrorToDynamoConsole($"Unhandled exception coming from package {faultyPkg.Name} was handled: {crashDetails.Details}"); Analytics.TrackException(ex, false); - - if (DynamoModel.IsTestMode) - { - // Rethrow the exception during testing. - throw ex; - } return; } } @@ -874,8 +876,8 @@ private void CrashGracefully(Exception ex, bool fatal = false) if (DynamoModel.IsTestMode) { - // Rethrow the exception during testing. - throw ex; + // Do not show the crash UI during tests. + return; } Model?.OnRequestsCrashPrompt(crashData); diff --git a/test/DynamoCoreWpfTests/PackageManager/PackageManagerViewExtensionTests.cs b/test/DynamoCoreWpfTests/PackageManager/PackageManagerViewExtensionTests.cs index af51fb2b1b2..41ee6c73f49 100644 --- a/test/DynamoCoreWpfTests/PackageManager/PackageManagerViewExtensionTests.cs +++ b/test/DynamoCoreWpfTests/PackageManager/PackageManagerViewExtensionTests.cs @@ -339,16 +339,11 @@ void DynamoConsoleLogger_LogErrorToDynamoConsole(string obj) } DynamoConsoleLogger.LogErrorToDynamoConsole += DynamoConsoleLogger_LogErrorToDynamoConsole; - - // Test live conditions of exception handling - using (Disposable.Create(() => { DynamoModel.IsTestMode = false; }, () => { DynamoModel.IsTestMode = true; })) + Assert.Throws(() => { - Assert.DoesNotThrow(() => - { - loader.LoadPackages(new List() { pkg }); - DispatcherUtil.DoEventsLoop(() => caughtExceptionFromPkg); - }); - } + loader.LoadPackages(new List() { pkg }); + DispatcherUtil.DoEventsLoop(() => caughtExceptionFromPkg); + }); Assert.AreEqual(1, count); Assert.IsTrue(caughtExceptionFromPkg);