-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Status.Error
does not reflect failed PowerShell cmdlets
#6149
Comments
Okay, I think I found the issue. This little line checks the previous error, when a cmdlet has failed. oh-my-posh/src/shell/scripts/omp.ps1 Line 226 in 7aefc7d
Unfortunately, the error log doesn't just contain entries of type See below the output of IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False ErrorRecord System.Object
True False ErrorRecord System.Object
True False ErrorRecord System.Object
True False ErrorRecord System.Object
True False ErrorRecord System.Object
True False ErrorRecord System.Object
True False ErrorRecord System.Object
True False ErrorRecord System.Object
True False ErrorRecord System.Object
True False ErrorRecord System.Object
True False ErrorRecord System.Object
True False ErrorRecord System.Object
True False ErrorRecord System.Object
True False ErrorRecord System.Object
True False ActionPreferenceStopException System.Management.Automation.RuntimeException
True False ErrorRecord System.Object
True False ErrorRecord System.Object
True False CommandNotFoundException System.Management.Automation.RuntimeException I wanted to test it locally, but couldn't find The solution could be to get the last error that is of type $global:Error | Where-Object { $_.GetType().Name -eq 'ErrorRecord' } | Select-Object -First 1 -ExpandProperty InvocationInfo I only realized this was the culprit, because looking at the code made me look at Select-Object:
Line |
226 | … bject { $_ -ne $null } | Select-Object -ExpandProperty InvocationInfo
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Property "InvocationInfo" cannot be found. |
Code of Conduct
What happened?
I wanted to add an update to my transient prompt to show red/green based on the error status of the last command.
Unfortunately, this didn't go as planned as
{{ .Segments.Status.Error }}
doesn't update when a PowerShell cmdlet fails. Like simply callingGet-ChildItem unknownfile
. This only sets$?
but not$LASTEXITCODE
.I tried to understand the relevant code in
omp.ps1
, but couldn't see if or what is not working.It works for native executables like git without issues, as those set
$LASTEXITCODE
.Theme
What OS are you seeing the problem on?
Windows
Which shell are you using?
powershell
Log output
The text was updated successfully, but these errors were encountered: