Skip to content

Commit 1030d81

Browse files
rkeithhilldaviwil
authored andcommitted
Fix DirectoryNotFoundException user is seeing in deep node_modules dir
Enumerating files in a dir shouldn't crash PSES for security, path length and errors from dir not found.
1 parent baddde3 commit 1030d81

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/PowerShellEditorServices/Workspace/Workspace.cs

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
using System.Collections.Generic;
99
using System.Linq;
1010
using System.IO;
11+
using System.Security;
1112
using System.Text;
12-
using System.Diagnostics;
1313

1414
namespace Microsoft.PowerShell.EditorServices
1515
{
@@ -249,7 +249,19 @@ private IEnumerable<string> RecursivelyEnumerateFiles(string folderPath)
249249
RecursivelyEnumerateFiles(dir));
250250
}
251251
}
252-
catch (UnauthorizedAccessException e)
252+
catch (DirectoryNotFoundException e)
253+
{
254+
this.logger.WriteException(
255+
$"Could not enumerate files in the path '{folderPath}' due to it being an invalid path",
256+
e);
257+
}
258+
catch (PathTooLongException e)
259+
{
260+
this.logger.WriteException(
261+
$"Could not enumerate files in the path '{folderPath}' due to the path being too long",
262+
e);
263+
}
264+
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
253265
{
254266
this.logger.WriteException(
255267
$"Could not enumerate files in the path '{folderPath}' due to the path not being accessible",

0 commit comments

Comments
 (0)