summaryrefslogtreecommitdiffstats
path: root/src/init
diff options
context:
space:
mode:
authorDavid Knaack <davidkna@users.noreply.github.com>2020-11-12 17:42:03 +0100
committerGitHub <noreply@github.com>2020-11-12 10:42:03 -0600
commita05be1844727bd6d3462cfbfc79a7dc7645f5b82 (patch)
tree74a7bde284ac9381a0bc09ea223b5a88b9c22709 /src/init
parentd648bb0e00b49911ccd3619cb89b3b142816b797 (diff)
fix(pwsh): fix crash on error in shell with old pwsh (#1861)
Handle missing Get-Error in powershell gracefully.
Diffstat (limited to 'src/init')
-rw-r--r--src/init/starship.ps112
1 files changed, 6 insertions, 6 deletions
diff --git a/src/init/starship.ps1 b/src/init/starship.ps1
index 9a731c6ef..6a870746f 100644
--- a/src/init/starship.ps1
+++ b/src/init/starship.ps1
@@ -19,12 +19,12 @@ function global:prompt {
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
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 = Get-Error | Where-Object {$_ -ne $null} | Select-Object -expand InvocationInfo
- # 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}
+ 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 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 ($null -ne $lastCmdletError -and $lastCmd.CommandLine -eq $lastCmdletError.Line) { 1 } else { $origLastExitCode }
}
$duration = [math]::Round(($lastCmd.EndExecutionTime - $lastCmd.StartExecutionTime).TotalMilliseconds)