Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerShell alias calling non-existent command returns 0 exit code failing test #1801

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

brycegbrazen
Copy link
Contributor

Adds failing test for #1800.

After digging into this there are three important Powershell automatic variables to take note of.

  • $LASTEXITCODE
  • $?
  • $ERROR

The first two, $LASTEXITCODE and $? are used in the code currently.

However, after testing the issue in PowerShell directly, it seems that the issue stems from an issue stemming from PowerShell itself.

When using aliases in PowerShell, if the command being called is not found, and error is printed to stderr, but neither the $LASTEXITCODE or $? variables are filled out correct to represent this.

For example, in PowerShell I ran:

PS C:\Users\bryce.gattis> hython
hython : The term 'hython' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ hython
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (hython:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\Users\bryce.gattis> $?
False
PS C:\Users\bryce.gattis> $LASTEXITCODE

Then I ran the following that does the same thing but using aliases:

PS C:\Users\bryce.gattis> function python() { hython @args }
PS C:\Users\bryce.gattis> python
hython : The term 'hython' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:21
+ function python() { hython @args }
+                     ~~~~~~
    + CategoryInfo          : ObjectNotFound: (hython:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS C:\Users\bryce.gattis> $?
True
PS C:\Users\bryce.gattis> $LASTEXITCODE

Interestingly, it seems like the $ERROR automatic variable, correctly captures the error message in both cases.

PS C:\Users\bryce.gattis> $ERROR
hython : The term 'hython' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:21
+ function python() { hython @args }
+                     ~~~~~~
    + CategoryInfo          : ObjectNotFound: (hython:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Not sure what the implications would be of additionally relying on the presence of an error in the $ERROR variable, but seems to be something that is slipping through the cracks right now. Perhaps there's a better fix for this?

Signed-off-by: brycegbrazen <bryce.gattis@brazenanimation.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant