Skip to content

Commit a537a35

Browse files
authored
CodeQuality: Removed logging for known exceptions (#16178)
1 parent af07aa3 commit a537a35

File tree

7 files changed

+83
-47
lines changed

7 files changed

+83
-47
lines changed

src/Files.App/Data/Commands/Manager/CommandManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ ActionsSettingsService.ActionsV2 is not null
483483
.SelectMany(command => command.HotKeys, (command, hotKey) => (Command: command, HotKey: hotKey))
484484
.ToImmutableDictionary(item => item.HotKey, item => item.Command);
485485

486-
App.Logger.LogWarning(ex, "The app found some keys in different commands are duplicated and are using default key bindings for those commands.");
486+
App.Logger.LogInformation(ex, "The app found some keys in different commands are duplicated and are using default key bindings for those commands.");
487487
}
488488
catch (Exception ex)
489489
{

src/Files.App/Helpers/PathNormalization.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static string NormalizePath(string path)
5454
}
5555
catch (Exception ex) when (ex is UriFormatException || ex is ArgumentException)
5656
{
57-
App.Logger.LogWarning(ex, path);
57+
App.Logger.LogDebug(ex, path);
5858
return path;
5959
}
6060
}

src/Files.App/Services/App/AppThemeModeService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Microsoft.UI.Windowing;
77
using Microsoft.UI.Xaml;
88
using Microsoft.UI.Xaml.Media;
9-
using Windows.Storage;
9+
using System.Runtime.InteropServices;
1010
using Windows.UI;
1111
using Windows.UI.ViewManagement;
1212

@@ -111,6 +111,10 @@ public void SetAppThemeMode(Window? window = null, AppWindowTitleBar? titleBar =
111111
if (callThemeModeChangedEvent)
112112
AppThemeModeChanged?.Invoke(null, EventArgs.Empty);
113113
}
114+
catch (COMException ex)
115+
{
116+
App.Logger.LogInformation(ex, "Failed to change theme mode of the app.");
117+
}
114118
catch (Exception ex)
115119
{
116120
App.Logger.LogWarning(ex, "Failed to change theme mode of the app.");

src/Files.App/Services/App/AppUpdateSideloadService.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,13 @@ public async Task CheckForUpdatesAsync()
138138
Logger?.LogWarning("SIDELOAD: Update not found.");
139139
}
140140
}
141-
catch (Exception e)
141+
catch (HttpRequestException ex)
142142
{
143-
Logger?.LogError(e, e.Message);
143+
Logger?.LogDebug(ex, ex.Message);
144+
}
145+
catch (Exception ex)
146+
{
147+
Logger?.LogError(ex, ex.Message);
144148
}
145149
}
146150

@@ -171,7 +175,7 @@ public async Task CheckAndUpdateFilesLauncherAsync()
171175
await srcExeFile.CopyAsync(destFolder, "Files.App.Launcher.exe", NameCollisionOption.ReplaceExisting);
172176
await srcHashFile.CopyAsync(destFolder, "Files.App.Launcher.exe.sha256", NameCollisionOption.ReplaceExisting);
173177

174-
App.Logger.LogInformation("Files.App.Launcher updated.");
178+
Logger?.LogInformation("Files.App.Launcher updated.");
175179
}
176180
}
177181

@@ -206,9 +210,13 @@ private async Task StartBackgroundDownloadAsync()
206210

207211
IsUpdateAvailable = true;
208212
}
209-
catch (Exception e)
213+
catch (IOException ex)
210214
{
211-
Logger?.LogError(e, e.Message);
215+
Logger?.LogDebug(ex, ex.Message);
216+
}
217+
catch (Exception ex)
218+
{
219+
Logger?.LogError(ex, ex.Message);
212220
}
213221
}
214222

src/Files.App/Utils/Cloud/CloudDrivesManager.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Microsoft.Extensions.Logging;
55
using System.Collections.Specialized;
6+
using System.IO;
67
using Windows.Storage;
78

89
namespace Files.App.Utils.Cloud
@@ -41,7 +42,7 @@ public static async Task UpdateDrivesAsync()
4142
{
4243
Text = provider.Name,
4344
Path = provider.SyncFolder,
44-
Type = DriveType.CloudDrive,
45+
Type = Data.Items.DriveType.CloudDrive,
4546
};
4647

4748
try
@@ -50,6 +51,14 @@ public static async Task UpdateDrivesAsync()
5051

5152
_ = MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() => cloudProviderItem.UpdatePropertiesAsync());
5253
}
54+
catch (FileNotFoundException ex)
55+
{
56+
_logger?.LogInformation(ex, "Failed to find the cloud folder");
57+
}
58+
catch (UnauthorizedAccessException ex)
59+
{
60+
_logger?.LogInformation(ex, " Failed to access the cloud folder");
61+
}
5362
catch (Exception ex)
5463
{
5564
_logger?.LogWarning(ex, "Cloud provider local folder couldn't be found");

src/Files.App/Utils/Storage/Operations/FileOperationsHelpers.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,11 @@ public static Task<bool> CreateOrUpdateLinkAsync(string linkSavePath, string tar
759759
});
760760
}
761761
}
762+
catch (UnauthorizedAccessException ex)
763+
{
764+
// Could not create shortcut
765+
App.Logger.LogInformation(ex, "Failed to create shortcut");
766+
}
762767
catch (Exception ex)
763768
{
764769
// Could not create shortcut

src/Files.App/ViewModels/Layouts/BaseLayoutViewModel.cs

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// Copyright (c) 2024 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4+
using Microsoft.Extensions.Logging;
45
using Microsoft.UI.Xaml;
56
using Microsoft.UI.Xaml.Input;
67
using System.IO;
8+
using System.Runtime.InteropServices;
79
using System.Windows.Input;
810
using Windows.ApplicationModel.DataTransfer;
911
using Windows.ApplicationModel.DataTransfer.DragDrop;
@@ -18,6 +20,7 @@ namespace Files.App.ViewModels.Layouts
1820
public sealed class BaseLayoutViewModel : IDisposable
1921
{
2022
protected ICommandManager Commands { get; } = Ioc.Default.GetRequiredService<ICommandManager>();
23+
private ILogger? Logger { get; } = Ioc.Default.GetRequiredService<ILogger<App>>();
2124

2225
private readonly IShellPage _associatedInstance;
2326

@@ -119,47 +122,54 @@ public async Task DragOverAsync(DragEventArgs e)
119122
}
120123
else
121124
{
122-
e.DragUIOverride.IsCaptionVisible = true;
123-
if (pwd.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal))
125+
try
124126
{
125-
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
126-
// Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
127-
e.AcceptedOperation = DataPackageOperation.Move | DataPackageOperation.Copy;
127+
e.DragUIOverride.IsCaptionVisible = true;
128+
if (pwd.StartsWith(Constants.UserEnvironmentPaths.RecycleBinPath, StringComparison.Ordinal))
129+
{
130+
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
131+
// Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
132+
e.AcceptedOperation = DataPackageOperation.Move | DataPackageOperation.Copy;
133+
}
134+
else if (e.Modifiers.HasFlag(DragDropModifiers.Alt) || e.Modifiers.HasFlag(DragDropModifiers.Control | DragDropModifiers.Shift))
135+
{
136+
e.DragUIOverride.Caption = string.Format("LinkToFolderCaptionText".GetLocalizedResource(), folderName);
137+
e.AcceptedOperation = DataPackageOperation.Link;
138+
}
139+
else if (e.Modifiers.HasFlag(DragDropModifiers.Control))
140+
{
141+
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
142+
e.AcceptedOperation = DataPackageOperation.Copy;
143+
}
144+
else if (e.Modifiers.HasFlag(DragDropModifiers.Shift))
145+
{
146+
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
147+
// Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
148+
e.AcceptedOperation = DataPackageOperation.Move | DataPackageOperation.Copy;
149+
}
150+
else if (draggedItems.Any(x =>
151+
x.Item is ZipStorageFile ||
152+
x.Item is ZipStorageFolder) ||
153+
ZipStorageFolder.IsZipPath(pwd))
154+
{
155+
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
156+
e.AcceptedOperation = DataPackageOperation.Copy;
157+
}
158+
else if (draggedItems.AreItemsInSameDrive(_associatedInstance.ShellViewModel.WorkingDirectory))
159+
{
160+
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
161+
// Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
162+
e.AcceptedOperation = DataPackageOperation.Move | DataPackageOperation.Copy;
163+
}
164+
else
165+
{
166+
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
167+
e.AcceptedOperation = DataPackageOperation.Copy;
168+
}
128169
}
129-
else if (e.Modifiers.HasFlag(DragDropModifiers.Alt) || e.Modifiers.HasFlag(DragDropModifiers.Control | DragDropModifiers.Shift))
170+
catch (COMException ex) when (ex.Message.Contains("RPC server is unavailable"))
130171
{
131-
e.DragUIOverride.Caption = string.Format("LinkToFolderCaptionText".GetLocalizedResource(), folderName);
132-
e.AcceptedOperation = DataPackageOperation.Link;
133-
}
134-
else if (e.Modifiers.HasFlag(DragDropModifiers.Control))
135-
{
136-
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
137-
e.AcceptedOperation = DataPackageOperation.Copy;
138-
}
139-
else if (e.Modifiers.HasFlag(DragDropModifiers.Shift))
140-
{
141-
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
142-
// Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
143-
e.AcceptedOperation = DataPackageOperation.Move | DataPackageOperation.Copy;
144-
}
145-
else if (draggedItems.Any(x =>
146-
x.Item is ZipStorageFile ||
147-
x.Item is ZipStorageFolder) ||
148-
ZipStorageFolder.IsZipPath(pwd))
149-
{
150-
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
151-
e.AcceptedOperation = DataPackageOperation.Copy;
152-
}
153-
else if (draggedItems.AreItemsInSameDrive(_associatedInstance.ShellViewModel.WorkingDirectory))
154-
{
155-
e.DragUIOverride.Caption = string.Format("MoveToFolderCaptionText".GetLocalizedResource(), folderName);
156-
// Some applications such as Edge can't raise the drop event by the Move flag (#14008), so we set the Copy flag as well.
157-
e.AcceptedOperation = DataPackageOperation.Move | DataPackageOperation.Copy;
158-
}
159-
else
160-
{
161-
e.DragUIOverride.Caption = string.Format("CopyToFolderCaptionText".GetLocalizedResource(), folderName);
162-
e.AcceptedOperation = DataPackageOperation.Copy;
172+
Logger?.LogDebug(ex, ex.Message);
163173
}
164174
}
165175
}

0 commit comments

Comments
 (0)