Repository navigation
Get-Command should not throw with white space argument - #10157
Ilya (iSazonov) wants to merge 5 commits into
Conversation
Rain Sallow (/u/ta11ow) (vexx32)
left a comment
There was a problem hiding this comment.
One minor nit for readability, but otherwise looks great! 👍
Co-Authored-By: Joel Sallow (/u/ta11ow) <32407840+vexx32@users.noreply.github.com>
|
Maybe related: #10165. Just mentioning because there are broader needs when it comes to whitespace in parameters that may be worth considering. |
| } | ||
|
|
||
| It "Get-Command `" `" does not throw" -Pending { | ||
| Get-Command " " | Should -Not -Throw |
There was a problem hiding this comment.
Is the expected behavior that it should not throw, or that it should throw in a specific way? (i.e. CommandNotFoundException).
Get-Command "`n"
throws CommandNotFoundException, so if a different type of whitespace results in nothing that would seem inconsistent?
There was a problem hiding this comment.
Given that it is possible to create an alias that contains a single whitespace (see #10165), Get-Command ' ' should return that command if it exists, or fail with a CommandNotFoundException if it does not.
There was a problem hiding this comment.
Guys,, do you really use whitespaces commands in your scripts and consider it a great practice?
There was a problem hiding this comment.
I stumbled upon this due to a bug in my own script; when a user enters invalid input PowerShell should respond appropriately so that the user knows what they did wrong.
CommandNotFoundException because space is not a valid command immediately tells you what your problem is and what you should do to fix it; IndexOutOfRangeException doesn't mean anything and you have to go digging through your script to find the non-obvious reason your script crashed. Failure to throw the right exception would also cause issues if you had an outer exception handler for CommandNotFoundException due to some requirement of your program
While I don't have any thoughts as to whether the behavior described in #10165 should be allowed, I would present that the resolution of #10165 issue should not impact the resolution of #10148; a command either exists or it doesn't - CommandSearcher should be able to process any valid string without crashing in an unexpected way
There was a problem hiding this comment.
Guys,, do you really use whitespaces commands in your scripts and consider it a great practice?
Of course not.
That doesn't change the fact that it can be done though, and I'm still with lordmilko: the error should be CommandNotFoundException if the command is not found.
|
We need a conclution in related issue before we could fix something |
PR Summary
Fix #10148
PR Context
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.