Skip to content

Make error message consistent when invalid script is passed to -File, better error when passed ambiguous arg - #4573

Merged
Ilya (iSazonov) merged 3 commits into
PowerShell:masterfrom
SteveL-MSFT:console-no
Aug 17, 2017
Merged

Make error message consistent when invalid script is passed to -File, better error when passed ambiguous arg#4573
Ilya (iSazonov) merged 3 commits into
PowerShell:masterfrom
SteveL-MSFT:console-no

Conversation

@SteveL-MSFT

@SteveL-MSFT Steve Lee (SteveL-MSFT) commented Aug 14, 2017

Copy link
Copy Markdown
Member

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:

PS C:\users\poker\repos\PowerShell> powershell -no -file foo
Invalid argument '-no', did you mean:

        -nologo
        -noexit
        -noprofile
        -noninteractive
PowerShell v6.0.0-beta.5-42-g3ed9a816b2452551aaad1ac1245a1cbb35e87612-dirty
Copyright (C) Microsoft Corporation. All rights reserved.

Enable -WindowStyle to work

Fix #4351

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe argument is better term and we can be shorter:

The argument '{0}' is not recognized as the name of a script file.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be validParameter.StartsWith(param, StringComparer.OrdinalIgnoreCase)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking to cover cases like: -format

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a test case for this

@lzybkr Jason Shirk (lzybkr) Aug 15, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd indent with spaces - we don't indent with tabs anywhere else that I know of.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will change

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Showing the banner after the error is weird and not like the other errors I reviewed.

@SteveL-MSFT Steve Lee (SteveL-MSFT) Aug 16, 2017

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@SteveL-MSFT Steve Lee (SteveL-MSFT) changed the title Make error message consistent when invalid script is passed to -File Make error message consistent when invalid script is passed to -File, better error when passed ambiguous arg Aug 16, 2017
@SteveL-MSFT
Steve Lee (SteveL-MSFT) force-pushed the console-no branch 2 times, most recently from a9d0bac to cb97564 Compare August 16, 2017 10:23

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#if !CORECLR is no longer relevant. Should we remove the parameters at all?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fixing that as part of enabling ApartmentState PR and not part of this PR

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe
#if !UNIX

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"did you mean:" - Do you want add something else?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The possible matches show up after this. See example above in the PR description.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should exclude this on Unix.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests is excluded on Unix so we could use our pattern "$PSDefaultParameterValues["it:skip"] = ..."

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parentheses can be removed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Aug 16, 2017

Copy link
Copy Markdown
Member Author

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.

@SteveL-MSFT
Steve Lee (SteveL-MSFT) force-pushed the console-no branch 2 times, most recently from bb83bb5 to ab1862b Compare August 16, 2017 13:01
@SteveL-MSFT Steve Lee (SteveL-MSFT) added the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Aug 16, 2017
@SteveL-MSFT

Copy link
Copy Markdown
Member Author

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

@SteveL-MSFT Steve Lee (SteveL-MSFT) added the Breaking-Change breaking change that may affect users label Aug 16, 2017

@lzybkr Jason Shirk (lzybkr) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@SteveL-MSFT

Copy link
Copy Markdown
Member Author

Jason Shirk (@lzybkr) are you referring to -WindowStyle and everything else as two commits?

@lzybkr

Copy link
Copy Markdown
Contributor

Yeah, -WindowStyle is buried at the bottom of your PR description, so it felt like it's own thing.

@SteveL-MSFT

Copy link
Copy Markdown
Member Author

Jason Shirk (@lzybkr) sure, I can make that two commits in the same PR.

@SteveL-MSFT

Copy link
Copy Markdown
Member Author

Split into 3 commits (Thanks Jason Shirk (@lzybkr) for the tip on git add -p!)

@SteveL-MSFT Steve Lee (SteveL-MSFT) added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Aug 16, 2017
@SteveL-MSFT

Copy link
Copy Markdown
Member Author

@PowerShell/powershell-committee reviewed this and is ok with changing the exit codes

@TravisEz13
Travis Plunk (TravisEz13) removed their request for review August 16, 2017 23:09
@iSazonov
Ilya (iSazonov) merged commit 45d1d20 into PowerShell:master Aug 17, 2017
@TravisEz13

Travis Plunk (TravisEz13) commented Aug 17, 2017

Copy link
Copy Markdown
Member

Ilya (@iSazonov), Jason Shirk (@lzybkr) and Steve Lee (@SteveL-MSFT) thanks as always!

@SteveL-MSFT
Steve Lee (SteveL-MSFT) deleted the console-no branch August 24, 2017 03:02
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj/PowerShell that referenced this pull request Aug 6, 2026
* Make invalid arg to -File consistent with -Command
Improve error message if ambiguous arg is passed to -File

* Update powershell console exit codes to match Unix standards

* Enable -WindowStyle to work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-Change breaking change that may affect users Committee-Reviewed PS-Committee has reviewed this and made a decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants