Skip to content

Commit 14ffe3c

Browse files
committed
Handle more exceptions
1 parent 617c62f commit 14ffe3c

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ public static string GetFileSize(string filePath)
107107
var fileInfo = new FileInfo(filePath);
108108
return ResultManager.ToReadableSize(fileInfo.Length, 2);
109109
}
110+
catch (FileNotFoundException)
111+
{
112+
Main.Context.API.LogError(ClassName, $"File not found: {filePath}");
113+
return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown");
114+
}
115+
catch (UnauthorizedAccessException)
116+
{
117+
Main.Context.API.LogError(ClassName, $"Access denied to file: {filePath}");
118+
return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown");
119+
}
110120
catch (Exception e)
111121
{
112122
Main.Context.API.LogException(ClassName, $"Failed to get file size for {filePath}", e);
@@ -128,6 +138,16 @@ public static string GetFileCreatedAt(string filePath, string previewPanelDateFo
128138
if (showFileAgeInPreviewPanel) result = $"{GetFileAge(createdDate)} - {formattedDate}";
129139
return result;
130140
}
141+
catch (FileNotFoundException)
142+
{
143+
Main.Context.API.LogError(ClassName, $"File not found: {filePath}");
144+
return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown");
145+
}
146+
catch (UnauthorizedAccessException)
147+
{
148+
Main.Context.API.LogError(ClassName, $"Access denied to file: {filePath}");
149+
return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown");
150+
}
131151
catch (Exception e)
132152
{
133153
Main.Context.API.LogException(ClassName, $"Failed to get file created date for {filePath}", e);
@@ -149,6 +169,16 @@ public static string GetFileLastModifiedAt(string filePath, string previewPanelD
149169
if (showFileAgeInPreviewPanel) result = $"{GetFileAge(lastModifiedDate)} - {formattedDate}";
150170
return result;
151171
}
172+
catch (FileNotFoundException)
173+
{
174+
Main.Context.API.LogError(ClassName, $"File not found: {filePath}");
175+
return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown");
176+
}
177+
catch (UnauthorizedAccessException)
178+
{
179+
Main.Context.API.LogError(ClassName, $"Access denied to file: {filePath}");
180+
return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown");
181+
}
152182
catch (Exception e)
153183
{
154184
Main.Context.API.LogException(ClassName, $"Failed to get file modified date for {filePath}", e);
@@ -171,6 +201,16 @@ public static string GetFolderSize(string folderPath)
171201

172202
return ResultManager.ToReadableSize(size, 2);
173203
}
204+
catch (FileNotFoundException)
205+
{
206+
Main.Context.API.LogError(ClassName, $"Folder not found: {folderPath}");
207+
return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown");
208+
}
209+
catch (UnauthorizedAccessException)
210+
{
211+
Main.Context.API.LogError(ClassName, $"Access denied to folder: {folderPath}");
212+
return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown");
213+
}
174214
catch (OperationCanceledException)
175215
{
176216
Main.Context.API.LogError(ClassName, $"Operation timed out while calculating folder size for {folderPath}");
@@ -197,6 +237,16 @@ public static string GetFolderCreatedAt(string folderPath, string previewPanelDa
197237
if (showFileAgeInPreviewPanel) result = $"{GetFileAge(createdDate)} - {formattedDate}";
198238
return result;
199239
}
240+
catch (FileNotFoundException)
241+
{
242+
Main.Context.API.LogError(ClassName, $"Folder not found: {folderPath}");
243+
return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown");
244+
}
245+
catch (UnauthorizedAccessException)
246+
{
247+
Main.Context.API.LogError(ClassName, $"Access denied to folder: {folderPath}");
248+
return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown");
249+
}
200250
catch (Exception e)
201251
{
202252
Main.Context.API.LogException(ClassName, $"Failed to get folder created date for {folderPath}", e);
@@ -218,6 +268,16 @@ public static string GetFolderLastModifiedAt(string folderPath, string previewPa
218268
if (showFileAgeInPreviewPanel) result = $"{GetFileAge(lastModifiedDate)} - {formattedDate}";
219269
return result;
220270
}
271+
catch (FileNotFoundException)
272+
{
273+
Main.Context.API.LogError(ClassName, $"Folder not found: {folderPath}");
274+
return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown");
275+
}
276+
catch (UnauthorizedAccessException)
277+
{
278+
Main.Context.API.LogError(ClassName, $"Access denied to folder: {folderPath}");
279+
return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown");
280+
}
221281
catch (Exception e)
222282
{
223283
Main.Context.API.LogException(ClassName, $"Failed to get folder modified date for {folderPath}", e);

0 commit comments

Comments
 (0)