Make error message consistent when invalid script is passed to -File, better error when passed ambiguous arg#4573
Conversation
There was a problem hiding this comment.
I believe argument is better term and we can be shorter:
The argument '{0}' is not recognized as the name of a script file.
e18b241 to
d6d9505
Compare
There was a problem hiding this comment.
Should this be validParameter.StartsWith(param, StringComparer.OrdinalIgnoreCase)?
There was a problem hiding this comment.
I was thinking to cover cases like: -format
There was a problem hiding this comment.
I'll add a test case for this
There was a problem hiding this comment.
I'd indent with spaces - we don't indent with tabs anywhere else that I know of.
There was a problem hiding this comment.
Showing the banner after the error is weird and not like the other errors I reviewed.
There was a problem hiding this comment.
I thought that was weird in general, but it seems consistent with other uses of WriteCommandLineError. Unless you know the reason it was like this, I'll change all uses to not show the banner.
a9d0bac to
cb97564
Compare
There was a problem hiding this comment.
#if !CORECLR is no longer relevant. Should we remove the parameters at all?
There was a problem hiding this comment.
I'm fixing that as part of enabling ApartmentState PR and not part of this PR
There was a problem hiding this comment.
"did you mean:" - Do you want add something else?
There was a problem hiding this comment.
The possible matches show up after this. See example above in the PR description.
There was a problem hiding this comment.
We should exclude this on Unix.
There was a problem hiding this comment.
All tests is excluded on Unix so we could use our pattern "$PSDefaultParameterValues["it:skip"] = ..."
There was a problem hiding this comment.
Parentheses can be removed.
eb660da to
951832a
Compare
|
Not sure why some of the new tests fail in AppVeyor but not on my desktop. Figured it out, need to redirect stderr to stdout. However, I noticed the tests fail on Mac because the exit code isn't being set, but still shows as passed overall. |
bb83bb5 to
ab1862b
Compare
|
Figured out why it's failing on non-Windows. It appears that exit codes from programs have to be in the range 0-255 and anything greater than 255 is mod 256. I verified this with a simple console c# app. In this case, the value for ExitCodeBadCommandLineParameter mod 256 == 0. Hmmm. Although a breaking change, I think we should conform to libc standards which means this error code should be 64 "command line usage error". We should also update all the other error codes that powershell console returns. In general, I don't think this should be a problem as typically 0 means success and non-0 means error so although a breaking change, I suspect it have limited real world impact. cc @PowerShell/powershell-committee |
be79184 to
5c6b694
Compare
lzybkr
left a comment
There was a problem hiding this comment.
I approve the changes, but there are 2 distinct fixes in the PR, so I think there should be 2 distinct commits.
Interactive add (git add -p) is an easy way to do that.
|
@lzybkr are you referring to -WindowStyle and everything else as two commits? |
|
Yeah, |
|
@lzybkr sure, I can make that two commits in the same PR. |
Improve error message if ambiguous arg is passed to -File
5c6b694 to
26f7db7
Compare
|
Split into 3 commits (Thanks @lzybkr for the tip on |
|
@PowerShell/powershell-committee reviewed this and is ok with changing the exit codes |
|
@iSazonov, @lzybkr and @SteveL-MSFT thanks as always! |
Since -File is now the positional parameter for powershell.exe, made the error message consistent with
-Command when passed an invalid file.
If ambiguous arg is passed, give a better error message:
Enable -WindowStyle to work
Fix #4351