Skip to content

Commit a406eb8

Browse files
Jack251970CopilotCopilot
authored
Fix ReportWindow crash when log directory is empty or missing (#4338)
* Initial plan * Fix ReportWindow crash when log directory is empty or doesn't exist Co-authored-by: Jack251970 <53996452+Jack251970@users.noreply.github.com> * Improve code comments Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 24f6c90 commit a406eb8

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

Flow.Launcher/ReportWindow.xaml.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,20 @@ private static string GetIssuesUrl(string website)
3838

3939
private void SetException(Exception exception)
4040
{
41-
var path = DataLocation.VersionLogDirectory;
42-
var directory = new DirectoryInfo(path);
43-
var log = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).First();
41+
FileInfo log = null;
42+
try
43+
{
44+
var path = DataLocation.VersionLogDirectory;
45+
var directory = new DirectoryInfo(path);
46+
if (directory.Exists)
47+
{
48+
log = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).FirstOrDefault();
49+
}
50+
}
51+
catch (Exception)
52+
{
53+
// Intentionally ignore all errors when trying to find the log file to avoid secondary crashes
54+
}
4455

4556
var websiteUrl = exception switch
4657
{
@@ -49,8 +60,11 @@ private void SetException(Exception exception)
4960
};
5061

5162
var paragraph = Hyperlink(Localize.reportWindow_please_open_issue(), websiteUrl);
52-
paragraph.Inlines.Add(Localize.reportWindow_upload_log(log.FullName));
53-
paragraph.Inlines.Add("\n");
63+
if (log is not null)
64+
{
65+
paragraph.Inlines.Add(Localize.reportWindow_upload_log(log.FullName));
66+
paragraph.Inlines.Add("\n");
67+
}
5468
paragraph.Inlines.Add(Localize.reportWindow_copy_below());
5569
ErrorTextbox.Document.Blocks.Add(paragraph);
5670

0 commit comments

Comments
 (0)