Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash handlers for Dynamo #14826

Merged
merged 24 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved
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;
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved

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);
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved
Model?.Logger?.LogError($"Unobserved task exception: {crashData.Details}");
Analytics.TrackException(e.Exception, true);
}
catch
{ }
}

private void CurrentDispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved
{
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));
}
}
}
}
Loading