mirror of
https://github.com/starship/starship.git
synced 2024-11-26 02:04:12 +01:00
fix(pwsh): fix crash on error in shell with old pwsh (#1861)
Handle missing Get-Error in powershell gracefully.
This commit is contained in:
parent
d648bb0e00
commit
a05be18447
@ -21,10 +21,10 @@ function global:prompt {
|
||||
# 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 = Get-Error | Where-Object {$_ -ne $null} | Select-Object -expand InvocationInfo
|
||||
$lastCmdletError = try { Get-Error | Where-Object { $_ -ne $null } | Select-Object -expand InvocationInfo } catch { $null }
|
||||
# We check if the las 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($lastCmd.CommandLine -eq $lastCmdletError.Line){1} else {$origLastExitCode}
|
||||
$lastExitCodeForPrompt = if ($null -ne $lastCmdletError -and $lastCmd.CommandLine -eq $lastCmdletError.Line) { 1 } else { $origLastExitCode }
|
||||
}
|
||||
|
||||
$duration = [math]::Round(($lastCmd.EndExecutionTime - $lastCmd.StartExecutionTime).TotalMilliseconds)
|
||||
|
Loading…
Reference in New Issue
Block a user