Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzart90 committed Jan 31, 2024
1 parent fb1de9b commit ca7dec4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ public static DynamoModel Start(IStartConfiguration configuration)
/// <param name="config">Start configuration</param>
protected DynamoModel(IStartConfiguration config)
{
DynamoModel.IsCrashing = false;

if (config is DefaultStartConfiguration defaultStartConfig)
{
// This is not exposed in IStartConfiguration to avoid a breaking change.
Expand Down
26 changes: 22 additions & 4 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
Expand Down Expand Up @@ -691,6 +692,7 @@ public struct StartConfiguration
protected DynamoViewModel(StartConfiguration startConfiguration)
{
Dispatcher.CurrentDispatcher.UnhandledException += CurrentDispatcher_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;

this.ShowLogin = startConfiguration.ShowLogin;

Expand Down Expand Up @@ -772,13 +774,28 @@ protected DynamoViewModel(StartConfiguration startConfiguration)
MLDataPipelineExtension = model.ExtensionManager.Extensions.OfType<DynamoMLDataPipelineExtension>().FirstOrDefault();
}


private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
try
{
var crashData = new CrashErrorReportArgs(e.Exception);
Model?.Logger?.LogError($"Unobserved task exception: {crashData.Details}");
Analytics.TrackException(e.Exception, true);
}
catch
{ }
}

private void CurrentDispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
if (e.Handled)
if (e.Handled || DynamoModel.IsCrashing)
{
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)
e.Handled = true;
CrashGracefully(e.Exception);
}
Expand All @@ -787,12 +804,12 @@ private void CrashGracefully(Exception ex)
{
try
{
Model?.Logger?.LogError($"Unhandled exception {ex.Message}");

DynamoModel.IsCrashing = true;
var crashData = new CrashErrorReportArgs(ex);
Model?.Logger?.LogError($"Unhandled exception: {crashData.Details} ");
Analytics.TrackException(ex, true);
Model?.OnRequestsCrashPrompt(new CrashErrorReportArgs(ex));

Model?.OnRequestsCrashPrompt(crashData);
Exit(false); // don't allow cancellation
}
catch
Expand Down Expand Up @@ -3491,6 +3508,7 @@ public ShutdownParams(
public bool PerformShutdownSequence(ShutdownParams shutdownParams)
{
Dispatcher.CurrentDispatcher.UnhandledException -= CurrentDispatcher_UnhandledException;
TaskScheduler.UnobservedTaskException -= TaskScheduler_UnobservedTaskException;

if (shutdownSequenceInitiated)
{
Expand Down
7 changes: 5 additions & 2 deletions src/DynamoSandbox/DynamoCoreSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,11 @@ private void ASMPreloadFailureHandler(string failureMessage)

private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var ex = e.ExceptionObject as Exception;
viewModel?.Model?.OnRequestsCrashPrompt(new CrashErrorReportArgs(ex));
if (!DynamoModel.IsCrashing)//Avoid duplicate CER reports
{
var ex = e.ExceptionObject as Exception;
viewModel?.Model?.OnRequestsCrashPrompt(new CrashErrorReportArgs(ex));
}
}
}
}

0 comments on commit ca7dec4

Please sign in to comment.