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 3 commits
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
66 changes: 52 additions & 14 deletions src/DynamoCoreWpf/Utilities/CrashReportTool.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dynamo.Core;
using Dynamo.Logging;
using Dynamo.Models;
using Dynamo.ViewModels;
using System;
Expand Down Expand Up @@ -116,6 +117,7 @@ internal static string CreateMiniDumpFile(string outputDir = null)
return outputFile;
}
}

return null;
}

Expand Down Expand Up @@ -176,11 +178,11 @@ internal static bool ShowCrashErrorReportWindow(DynamoViewModel viewModel, Crash
}

DynamoModel model = viewModel?.Model;

string cerToolDir = !string.IsNullOrEmpty(model?.CERLocation) ?
model?.CERLocation : FindCERToolInInstallLocations();

string cerToolDir = !string.IsNullOrEmpty(model.CERLocation) ?
model.CERLocation : FindCERToolInInstallLocations();

var cerToolPath = Path.Combine(cerToolDir, CERDllName);
var cerToolPath = !string.IsNullOrEmpty(cerToolDir) ? Path.Combine(cerToolDir, CERDllName) : string.Empty;
if (string.IsNullOrEmpty(cerToolPath) || !File.Exists(cerToolPath))
{
model?.Logger?.LogError($"The CER tool was not found at location {cerToolPath}");
Expand All @@ -199,18 +201,34 @@ internal static bool ShowCrashErrorReportWindow(DynamoViewModel viewModel, Crash
{
string logFile = Path.Combine(cerDir.FullName, "DynamoLog.log");

File.Copy(model.Logger.LogPath, logFile);
// might be usefull to dump all loaded Packages into
// the log at this point.
filesToSend.Add(logFile);
try
{
File.Copy(model.Logger.LogPath, logFile);
// might be usefull to dump all loaded Packages into
// the log at this point.
filesToSend.Add(logFile);
}
catch(Exception ex)
{
model?.Logger?.LogError($"Failed to send Log file to CER due to the following error : {ex.Message}");
}
}

if (args.SendSettingsFile && model != null)
{
string settingsFile = Path.Combine(cerDir.FullName, "DynamoSettings.xml");
File.Copy(model.PathManager.PreferenceFilePath, settingsFile);

filesToSend.Add(settingsFile);
try
{
File.Copy(model.PathManager.PreferenceFilePath, settingsFile);

filesToSend.Add(settingsFile);

}
catch (Exception ex)
{
model?.Logger?.LogError($"Failed to send Settings file to CER due to the following error : {ex.Message}");
}
}

if (args.HasDetails())
Expand All @@ -222,7 +240,14 @@ internal static bool ShowCrashErrorReportWindow(DynamoViewModel viewModel, Crash

if (args.SendRecordedCommands && viewModel != null)
{
filesToSend.Add(viewModel.DumpRecordedCommands());
try
{
filesToSend.Add(viewModel.DumpRecordedCommands());
}
catch (Exception ex)
{
model?.Logger?.LogError($"Failed to send Commands file to CER due to the following error : {ex.Message}");
}
}

string appConfig = "";
Expand All @@ -234,11 +259,24 @@ internal static bool ShowCrashErrorReportWindow(DynamoViewModel viewModel, Crash
$"session_start_count=\"0\" session_clean_close_count=\"0\" current_session_length=\"0\" />";
}

string dynName = viewModel?.Model.CurrentWorkspace.Name;
string dynName = model?.CurrentWorkspace.Name;

var miniDumpFilePath = CreateMiniDumpFile(cerDir.FullName);
var upiConfigFilePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "upiconfig.xml");
var miniDumpFilePath = string.Empty;
try
{
miniDumpFilePath = CreateMiniDumpFile(cerDir.FullName);
}
catch (Exception ex)
{
model?.Logger?.LogError($"Failed to generate minidump file for CER due to the following error : {ex.Message}");
}

if (string.IsNullOrEmpty(miniDumpFilePath))
{
return false;
}

var upiConfigFilePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "upiconfig.xml");
using (var cerDLL = new CerDLL(cerToolPath))
{
cerDLL.ToggleCER(true);
Expand Down
37 changes: 37 additions & 0 deletions src/DynamoSandbox/DynamoCoreSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Threading;
using Dynamo.Applications;
using Dynamo.Controls;
using Dynamo.Core;
Expand Down Expand Up @@ -58,6 +59,9 @@ public void RunApplication(Application app)
{
try
{
Dispatcher.CurrentDispatcher.UnhandledException += CurrentDispatcher_UnhandledException;
pinzart90 marked this conversation as resolved.
Show resolved Hide resolved
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved

// This line validates if the WebView2 Runtime is installed in the computer before launching DynamoSandbox,
// if is not we return and then exit Dynamo Sandbox
if (!WebView2Utilities.ValidateWebView2RuntimeInstalled())
Expand Down Expand Up @@ -161,5 +165,38 @@ private void ASMPreloadFailureHandler(string failureMessage)
{
MessageBoxService.Show(failureMessage, "DynamoSandbox", MessageBoxButton.OK, MessageBoxImage.Warning);
}

private void CurrentDispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
if (e.Handled)
{
return;
}

e.Handled = true;
CrashGracefully(e.Exception);
}

private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var ex = e.ExceptionObject as Exception;
pinzart90 marked this conversation as resolved.
Show resolved Hide resolved
CrashGracefully(ex);
}

private void CrashGracefully(Exception ex)
{
try
{
viewModel?.Model?.Logger?.LogError($"Unhandled exception {ex.Message}");

DynamoModel.IsCrashing = true;
Analytics.TrackException(ex, true);
CrashReportTool.ShowCrashErrorReportWindow(viewModel, new Dynamo.Core.CrashErrorReportArgs(ex));
}
catch
{ }
pinzart90 marked this conversation as resolved.
Show resolved Hide resolved

viewModel?.Exit(false); // don't allow cancellation
}
}
}
1 change: 1 addition & 0 deletions src/DynamoSandbox/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Threading;

namespace DynamoSandbox
{
Expand Down
Loading