diff --git a/src/System.Management.Automation/engine/CommandSearcher.cs b/src/System.Management.Automation/engine/CommandSearcher.cs index a703b2ec28c..002535f2da9 100644 --- a/src/System.Management.Automation/engine/CommandSearcher.cs +++ b/src/System.Management.Automation/engine/CommandSearcher.cs @@ -565,7 +565,7 @@ private Collection GetNextFromPathUsingWildcards(string command, out Pro } provider = null; - return null; + return new Collection(); } private static bool checkPath(string path, string commandName) diff --git a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 index 030301477c2..fa3e957e80b 100644 --- a/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 +++ b/test/powershell/engine/Basic/CommandDiscovery.Tests.ps1 @@ -205,4 +205,10 @@ Describe "Command Discovery tests" -Tags "CI" { } } } + + Context "error cases" { + It 'Get-Command "less `"-PsPage %db?B of %DoesNotExist:`"" should throw Drive not found' { + {Get-Command -Name "less `"-PsPage %db?B of %DoesNotExist:`""} | Should -Throw -ErrorId 'DriveNotFound' -Because "The drive 'DoesNotExist:' should not exist" + } + } }