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

DYN-6606: Make ShowCrashErrorReportWindow more robust #14862

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Changes from 2 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
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(logFile))
{
File.Copy(model.Logger.LogPath, logFile);
filesToSend.Add(logFile);
}
else
{
model?.Logger?.LogError($"Failed to add DynamoLog.log to CER with the following error : {logFile} 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(settingsFile))
{
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved
File.Copy(model.PathManager.PreferenceFilePath, settingsFile);

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

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

if (args.SendRecordedCommands && viewModel != null)
{
filesToSend.Add(viewModel.DumpRecordedCommands());
try
{
filesToSend.Add(viewModel.DumpRecordedCommands());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need try-catch here? This is just adding to a list.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if DumpRecordedCommands throws an exception ? It should not short circuit the CER report

}
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
Loading