Skip to content

Commit

Permalink
DYN-6606: Make ShowCrashErrorReportWindow more robust (#14862)
Browse files Browse the repository at this point in the history
* Make ShowCrashErrorReportWindow more robust

* Address review comments. Also check minidump.

* Don't add code late at night
  • Loading branch information
sm6srw authored Jan 18, 2024
1 parent 12c5026 commit b8d7aaf
Showing 1 changed file with 56 additions and 14 deletions.
70 changes: 56 additions & 14 deletions src/DynamoCoreWpf/Utilities/CrashReportTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,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 = !string.IsNullOrEmpty(cerToolDir) ? Path.Combine(cerToolDir, CERDllName) : string.Empty;

var cerToolPath = Path.Combine(cerToolDir, CERDllName);
if (string.IsNullOrEmpty(cerToolPath) || !File.Exists(cerToolPath))
{
model?.Logger?.LogError($"The CER tool was not found at location {cerToolPath}");
Expand All @@ -199,30 +200,57 @@ 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);
if(File.Exists(model.Logger.LogPath))
{
File.Copy(model.Logger.LogPath, logFile);
filesToSend.Add(logFile);
}
else
{
model?.Logger?.LogError($"Failed to add DynamoLog.log to CER with the following error : {model.Logger.LogPath} Not Found");
}
}

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

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

filesToSend.Add(settingsFile);
}
else
{
model?.Logger?.LogError($"Failed to add DynamoSettings.xml to CER with the following error : {model.PathManager.PreferenceFilePath} Not Found");
}
}

if (args.HasDetails())
{
var stackTracePath = Path.Combine(cerDir.FullName, "StackTrace.log");
File.WriteAllText(stackTracePath, args.Details);
filesToSend.Add(stackTracePath);
try
{
File.WriteAllText(stackTracePath, args.Details);
filesToSend.Add(stackTracePath);
}
catch (Exception ex)
{
model?.Logger?.LogError($"Failed to add StackTrace.log to CER with the following error : {ex.Message}");
}
}

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

string appConfig = "";
Expand All @@ -234,9 +262,23 @@ 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 = 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 miniDumpFilePath = CreateMiniDumpFile(cerDir.FullName);
var upiConfigFilePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "upiconfig.xml");

using (var cerDLL = new CerDLL(cerToolPath))
Expand Down

0 comments on commit b8d7aaf

Please sign in to comment.