Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzart90 committed Apr 25, 2024
1 parent 1bcce09 commit 928e049
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
26 changes: 14 additions & 12 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NotImplementedException>(() =>
{
Assert.DoesNotThrow(() =>
{
loader.LoadPackages(new List<Package>() { pkg });
DispatcherUtil.DoEventsLoop(() => caughtExceptionFromPkg);
});
}
loader.LoadPackages(new List<Package>() { pkg });
DispatcherUtil.DoEventsLoop(() => caughtExceptionFromPkg);
});

Assert.AreEqual(1, count);
Assert.IsTrue(caughtExceptionFromPkg);
Expand Down

0 comments on commit 928e049

Please sign in to comment.