diff options
author | Chrissy LeMaire <potatoqualitee@users.noreply.github.com> | 2021-07-13 22:31:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-13 16:31:14 -0400 |
commit | c9249dbe0b8e508b0067512e1accdf80e4d014ec (patch) | |
tree | 09360a087edfb2d8bfcd01d84fb10bee0c2f44cc | |
parent | 0228a53c9fcffec602f7cc9cc4faf17f50ea812a (diff) |
fix(pwsh): replace Get-Error with $error[0] (#2873)
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.
-rw-r--r-- | src/init/starship.ps1 | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/init/starship.ps1 b/src/init/starship.ps1 index e5a1fb148..e5e36a54d 100644 --- a/src/init/starship.ps1 +++ b/src/init/starship.ps1 @@ -81,8 +81,8 @@ function global:prompt { if ($lastCmd = Get-History -Count 1) { # In case we have a False on the Dollar hook, we know there's an error. if (-not $origDollarQuestion) { - # We retrieve the InvocationInfo from the most recent error. - $lastCmdletError = try { Get-Error | Where-Object { $_ -ne $null } | Select-Object -expand InvocationInfo } catch { $null } + # We retrieve the InvocationInfo from the most recent error using $error[0] + $lastCmdletError = try { $error[0] | Where-Object { $_ -ne $null } | Select-Object -ExpandProperty InvocationInfo } catch { $null } # We check if the last command executed matches the line that caused the last error, in which case we know # it was an internal Powershell command, otherwise, there MUST be an error code. $lastExitCodeForPrompt = if ($null -ne $lastCmdletError -and $lastCmd.CommandLine -eq $lastCmdletError.Line) { 1 } else { $origLastExitCode } |