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

fix: PowerShell init - replace Get-Error with $error[0] #2873

Merged
merged 2 commits into from Jul 13, 2021
Merged

fix: PowerShell init - replace Get-Error with $error[0] #2873

merged 2 commits into from Jul 13, 2021

Conversation

potatoqualitee
Copy link
Contributor

Description

Get-Error does not exist in all versions of PowerShell, and attempting to use it on machines where it does not exist pollutes $error. Someone may be tempted to use -ErrorAction Ignore but since the command does not exist, it still ends up in $error

This is a dual bug fix because it actually gets errors on all machines now and it does not pollute $error.

Motivation and Context

In looking for unrelated errors, I kept seeing an error about Get-Error not existing, and narrowed it down to starship.

I also changed -expand to -ExpandProperty while I was at it because it is best practice.

Screenshots (if appropriate):

image

$error[0] exists in all versions of PowerShell and will not cause issues even if there are no errors

image

How Has This Been Tested?

  • I have tested using MacOS
  • I have tested using Linux
  • I have tested using Windows

I didn't test within starship, but I did at the console. First, I opened a fresh console with no errors and you can see that attempting to get $lastCmdletError did not cause errors. Next, I forced an error, then I ran the line again and you can see that it did get $lastCmdletError

image

Checklist:

  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.

There are no other instances of Get-Error, including tests, so this was likely the only place it was being used

@potatoqualitee
Copy link
Contributor Author

For anyone who wants a workaround right now, you can create the following function in your $profile right before you execute starship:

    function Get-Error {
        $error[0]
    }

@andytom andytom requested a review from a team July 10, 2021 20:19
Copy link
Member

@matchai matchai left a comment

Choose a reason for hiding this comment

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

Looks good to me! 👍
Thank you for your contribution, Chrissy! 😄

@matchai matchai merged commit c9249db into starship:master Jul 13, 2021
@potatoqualitee potatoqualitee deleted the fixps branch July 13, 2021 21:31
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.

None yet

2 participants