From 5035dc6754b5d22eebd1000ab47f17d8d1de4643 Mon Sep 17 00:00:00 2001 From: Davide Giacometti Date: Mon, 17 Jan 2022 23:56:04 +0100 Subject: [PATCH] [PTRun][Program]Fix FileSystemWatcher Crash (#15480) * fix FileSystemWatcher crash * catch general exception --- .../Storage/Win32ProgramFileSystemWatchers.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Storage/Win32ProgramFileSystemWatchers.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Storage/Win32ProgramFileSystemWatchers.cs index e20e890037..990f0c94e6 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Storage/Win32ProgramFileSystemWatchers.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Storage/Win32ProgramFileSystemWatchers.cs @@ -40,9 +40,15 @@ namespace Microsoft.Plugin.Program.Storage var invalidPaths = new List(); foreach (var path in paths) { - if (!Directory.Exists(path)) + try { - Log.Warn($"Directory {path} does not exist and will be ignored", typeof(Win32ProgramFileSystemWatchers)); + Directory.GetFiles(path); + } +#pragma warning disable CA1031 // Do not catch general exception types + catch (Exception ex) +#pragma warning restore CA1031 // Do not catch general exception types + { + Log.Exception($"Failed to get files in {path}", ex, typeof(Win32ProgramFileSystemWatchers)); invalidPaths.Add(path); } }