From 5acbf76c3ee3ee97dffed5cbe91cf6b5bd60dd7f Mon Sep 17 00:00:00 2001 From: Aparajit Pratap Date: Fri, 12 Jan 2024 11:22:03 -0500 Subject: [PATCH 1/4] add unhandled exception handler to viewmodel --- .../ViewModels/Core/DynamoViewModel.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs index 3a9f5248f07..c64720205c1 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs @@ -22,6 +22,7 @@ using Dynamo.Graph.Nodes; using Dynamo.Graph.Workspaces; using Dynamo.Interfaces; +using Dynamo.Logging; using Dynamo.Models; using Dynamo.PackageManager; using Dynamo.PackageManager.UI; @@ -46,6 +47,7 @@ using DynamoUtilities; using ICSharpCode.AvalonEdit; using PythonNodeModels; +using static Dynamo.ViewModels.SearchViewModel; using ISelectable = Dynamo.Selection.ISelectable; using WpfResources = Dynamo.Wpf.Properties.Resources; @@ -675,6 +677,8 @@ public struct StartConfiguration protected DynamoViewModel(StartConfiguration startConfiguration) { + Dispatcher.CurrentDispatcher.UnhandledException += CurrentDispatcher_UnhandledException; + this.ShowLogin = startConfiguration.ShowLogin; // initialize core data structures @@ -754,6 +758,32 @@ protected DynamoViewModel(StartConfiguration startConfiguration) FileTrustViewModel = new FileTrustWarningViewModel(); } + private void CurrentDispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) + { + if (e.Handled) + { + return; + } + + e.Handled = true; + CrashGracefully(e.Exception); + } + + private void CrashGracefully(Exception ex) + { + try + { + Model?.Logger?.LogError($"Unhandled exception {ex.Message}"); + + DynamoModel.IsCrashing = true; + Analytics.TrackException(ex, true); + CrashReportTool.ShowCrashErrorReportWindow(this, new Dynamo.Core.CrashErrorReportArgs(ex)); + } + catch + { } + Exit(false); // don't allow cancellation + } + /// /// Sets up the provided object and /// adds it to the Watch3DViewModels collection. @@ -3412,6 +3442,8 @@ public ShutdownParams( /// public bool PerformShutdownSequence(ShutdownParams shutdownParams) { + Dispatcher.CurrentDispatcher.UnhandledException -= CurrentDispatcher_UnhandledException; + if (shutdownSequenceInitiated) { // There was a prior call to shutdown. This could happen for example From 13c30b421eb4b97e7010fe73977f2a03106327e8 Mon Sep 17 00:00:00 2001 From: Aparajit Pratap Date: Fri, 12 Jan 2024 11:27:42 -0500 Subject: [PATCH 2/4] cleanup --- src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs index c64720205c1..b8594728598 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs @@ -31,7 +31,6 @@ using Dynamo.Services; using Dynamo.UI; using Dynamo.UI.Prompts; -using Dynamo.Updates; using Dynamo.Utilities; using Dynamo.Visualization; using Dynamo.Wpf.Interfaces; @@ -47,7 +46,6 @@ using DynamoUtilities; using ICSharpCode.AvalonEdit; using PythonNodeModels; -using static Dynamo.ViewModels.SearchViewModel; using ISelectable = Dynamo.Selection.ISelectable; using WpfResources = Dynamo.Wpf.Properties.Resources; From 379782fb4288c2edd814bb137dbe3af83c59f31c Mon Sep 17 00:00:00 2001 From: Aparajit Pratap Date: Wed, 17 Jan 2024 23:33:37 -0500 Subject: [PATCH 3/4] add backup crash dialog if CER is unavailable --- src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs index b8594728598..c5861e1d8c9 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs @@ -14,6 +14,7 @@ using System.Windows.Media; using System.Windows.Threading; using Dynamo.Configuration; +using Dynamo.Core; using Dynamo.Engine; using Dynamo.Exceptions; using Dynamo.Graph; @@ -775,7 +776,7 @@ private void CrashGracefully(Exception ex) DynamoModel.IsCrashing = true; Analytics.TrackException(ex, true); - CrashReportTool.ShowCrashErrorReportWindow(this, new Dynamo.Core.CrashErrorReportArgs(ex)); + Model?.OnRequestsCrashPrompt(new CrashErrorReportArgs(ex)); } catch { } From 9231c5ca8a4e57c34b939a8f08198f722d151bb9 Mon Sep 17 00:00:00 2001 From: Aparajit Pratap Date: Thu, 18 Jan 2024 20:07:43 -0500 Subject: [PATCH 4/4] catch any exceptions thrown from handler itself --- src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs index c5861e1d8c9..eb1d5395435 100644 --- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs @@ -777,10 +777,11 @@ private void CrashGracefully(Exception ex) DynamoModel.IsCrashing = true; Analytics.TrackException(ex, true); Model?.OnRequestsCrashPrompt(new CrashErrorReportArgs(ex)); + + Exit(false); // don't allow cancellation } catch { } - Exit(false); // don't allow cancellation } ///