From a406eb83e1618c7f95510b27b55e87d3731d6d0c Mon Sep 17 00:00:00 2001 From: Jack Ye Date: Tue, 10 Mar 2026 20:29:09 +0800 Subject: [PATCH] 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> --- Flow.Launcher/ReportWindow.xaml.cs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher/ReportWindow.xaml.cs b/Flow.Launcher/ReportWindow.xaml.cs index bb0ce0073..b2c95cbe2 100644 --- a/Flow.Launcher/ReportWindow.xaml.cs +++ b/Flow.Launcher/ReportWindow.xaml.cs @@ -38,9 +38,20 @@ namespace Flow.Launcher private void SetException(Exception exception) { - var path = DataLocation.VersionLogDirectory; - var directory = new DirectoryInfo(path); - var log = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).First(); + FileInfo log = null; + try + { + var path = DataLocation.VersionLogDirectory; + var directory = new DirectoryInfo(path); + if (directory.Exists) + { + log = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).FirstOrDefault(); + } + } + catch (Exception) + { + // Intentionally ignore all errors when trying to find the log file to avoid secondary crashes + } var websiteUrl = exception switch { @@ -49,8 +60,11 @@ namespace Flow.Launcher }; var paragraph = Hyperlink(Localize.reportWindow_please_open_issue(), websiteUrl); - paragraph.Inlines.Add(Localize.reportWindow_upload_log(log.FullName)); - paragraph.Inlines.Add("\n"); + if (log is not null) + { + paragraph.Inlines.Add(Localize.reportWindow_upload_log(log.FullName)); + paragraph.Inlines.Add("\n"); + } paragraph.Inlines.Add(Localize.reportWindow_copy_below()); ErrorTextbox.Document.Blocks.Add(paragraph);