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>
This commit is contained in:
Jack Ye 2026-03-10 20:29:09 +08:00 committed by GitHub
parent 24f6c90f72
commit a406eb83e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);