From e557b901e2a04eb33a538889de70fda1cbbbdc9f Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Fri, 3 Nov 2017 23:49:47 -0600 Subject: [PATCH] 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. --- .../Workspace/Workspace.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/PowerShellEditorServices/Workspace/Workspace.cs b/src/PowerShellEditorServices/Workspace/Workspace.cs index f5deee6c8..8cf038e59 100644 --- a/src/PowerShellEditorServices/Workspace/Workspace.cs +++ b/src/PowerShellEditorServices/Workspace/Workspace.cs @@ -8,8 +8,8 @@ using System.Collections.Generic; using System.Linq; using System.IO; +using System.Security; using System.Text; -using System.Diagnostics; namespace Microsoft.PowerShell.EditorServices { @@ -249,7 +249,19 @@ private IEnumerable RecursivelyEnumerateFiles(string folderPath) RecursivelyEnumerateFiles(dir)); } } - catch (UnauthorizedAccessException e) + catch (DirectoryNotFoundException e) + { + this.logger.WriteException( + $"Could not enumerate files in the path '{folderPath}' due to it being an invalid path", + e); + } + catch (PathTooLongException e) + { + this.logger.WriteException( + $"Could not enumerate files in the path '{folderPath}' due to the path being too long", + e); + } + catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException) { this.logger.WriteException( $"Could not enumerate files in the path '{folderPath}' due to the path not being accessible",