Skip to content

Commit b8d7aaf

Browse files
authored
DYN-6606: Make ShowCrashErrorReportWindow more robust (#14862)
* Make ShowCrashErrorReportWindow more robust * Address review comments. Also check minidump. * Don't add code late at night
1 parent 12c5026 commit b8d7aaf

File tree

1 file changed

+56
-14
lines changed

1 file changed

+56
-14
lines changed

src/DynamoCoreWpf/Utilities/CrashReportTool.cs

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,11 @@ internal static bool ShowCrashErrorReportWindow(DynamoViewModel viewModel, Crash
177177

178178
DynamoModel model = viewModel?.Model;
179179

180-
string cerToolDir = !string.IsNullOrEmpty(model.CERLocation) ?
181-
model.CERLocation : FindCERToolInInstallLocations();
180+
string cerToolDir = !string.IsNullOrEmpty(model?.CERLocation) ?
181+
model?.CERLocation : FindCERToolInInstallLocations();
182+
183+
var cerToolPath = !string.IsNullOrEmpty(cerToolDir) ? Path.Combine(cerToolDir, CERDllName) : string.Empty;
182184

183-
var cerToolPath = Path.Combine(cerToolDir, CERDllName);
184185
if (string.IsNullOrEmpty(cerToolPath) || !File.Exists(cerToolPath))
185186
{
186187
model?.Logger?.LogError($"The CER tool was not found at location {cerToolPath}");
@@ -199,30 +200,57 @@ internal static bool ShowCrashErrorReportWindow(DynamoViewModel viewModel, Crash
199200
{
200201
string logFile = Path.Combine(cerDir.FullName, "DynamoLog.log");
201202

202-
File.Copy(model.Logger.LogPath, logFile);
203-
// might be usefull to dump all loaded Packages into
204-
// the log at this point.
205-
filesToSend.Add(logFile);
203+
if(File.Exists(model.Logger.LogPath))
204+
{
205+
File.Copy(model.Logger.LogPath, logFile);
206+
filesToSend.Add(logFile);
207+
}
208+
else
209+
{
210+
model?.Logger?.LogError($"Failed to add DynamoLog.log to CER with the following error : {model.Logger.LogPath} Not Found");
211+
}
206212
}
207213

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

213-
filesToSend.Add(settingsFile);
218+
if (File.Exists(model.PathManager.PreferenceFilePath))
219+
{
220+
File.Copy(model.PathManager.PreferenceFilePath, settingsFile);
221+
222+
filesToSend.Add(settingsFile);
223+
}
224+
else
225+
{
226+
model?.Logger?.LogError($"Failed to add DynamoSettings.xml to CER with the following error : {model.PathManager.PreferenceFilePath} Not Found");
227+
}
214228
}
215229

216230
if (args.HasDetails())
217231
{
218232
var stackTracePath = Path.Combine(cerDir.FullName, "StackTrace.log");
219-
File.WriteAllText(stackTracePath, args.Details);
220-
filesToSend.Add(stackTracePath);
233+
try
234+
{
235+
File.WriteAllText(stackTracePath, args.Details);
236+
filesToSend.Add(stackTracePath);
237+
}
238+
catch (Exception ex)
239+
{
240+
model?.Logger?.LogError($"Failed to add StackTrace.log to CER with the following error : {ex.Message}");
241+
}
221242
}
222243

223244
if (args.SendRecordedCommands && viewModel != null)
224245
{
225-
filesToSend.Add(viewModel.DumpRecordedCommands());
246+
try
247+
{
248+
filesToSend.Add(viewModel.DumpRecordedCommands());
249+
}
250+
catch (Exception ex)
251+
{
252+
model?.Logger?.LogError($"Failed to add recorded commands to CER with the following error : {ex.Message}");
253+
}
226254
}
227255

228256
string appConfig = "";
@@ -234,9 +262,23 @@ internal static bool ShowCrashErrorReportWindow(DynamoViewModel viewModel, Crash
234262
$"session_start_count=\"0\" session_clean_close_count=\"0\" current_session_length=\"0\" />";
235263
}
236264

237-
string dynName = viewModel?.Model.CurrentWorkspace.Name;
265+
string dynName = model?.CurrentWorkspace.Name;
266+
267+
var miniDumpFilePath = string.Empty;
268+
try
269+
{
270+
miniDumpFilePath = CreateMiniDumpFile(cerDir.FullName);
271+
}
272+
catch (Exception ex)
273+
{
274+
model?.Logger?.LogError($"Failed to generate minidump file for CER due to the following error : {ex.Message}");
275+
}
276+
277+
if (string.IsNullOrEmpty(miniDumpFilePath))
278+
{
279+
return false;
280+
}
238281

239-
var miniDumpFilePath = CreateMiniDumpFile(cerDir.FullName);
240282
var upiConfigFilePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "upiconfig.xml");
241283

242284
using (var cerDLL = new CerDLL(cerToolPath))

0 commit comments

Comments
 (0)