PowerLine
PowerLine copied to clipboard
"Exception thrown from prompt block" even when the exception is handled within the block
Run the following to test this issue:
$Prompt.Add( { try{throw "error"}catch{} } )
The result is a WARNING:
WARNING: Exception thrown from prompt block. Check $PromptErrors. To suppress this message, Set-PowerLine -HideError
WARNING: Exception in PowerLinePrompt
$PromptErrors contains:
Name : 3 { try{throw "error"}catch{} }
Value : {System.Management.Automation.RuntimeException}
- PowerLine Module Version 3.4.0
- Pansies Module Version 2.3.1 Tested on:
- Arch Linux with PowerShell Core 7.1.5
- Windows 10 with PowerShell 5.1.19041.1237
Expected behavior:
- When an exception is captured, the error should not be displayed.
Thought it might do with capturing of the error stream, but this caused the same behavior:
$Prompt.Add( { $(try{throw "error"}catch{} *>&1)} )
You'll have to Set-PowerLinePrompt -HideErrors
PowerShell doesn't care that you're handling the error. I filed https://github.com/PowerShell/PowerShell/issues/3768 about this years ago.
Basically, we're always invoking your scriptblock within a script cmdlet with -ErrorVariable, something like this:
. { [CmdletBinding()]param()
try { throw "error" } catch {}
} -ErrorVariable logging
It doesn't matter that you handled the exception -- it still shows up in the ErrorVariable, and there's nothing I can do about it except ignore all the errors (the way I do, if you set -HideErrors true).
How about a way to ignore the error for a specific variable - base on output - or maybe even adding a custom object to the ErrorVariable?
I understand it's hacky as hell, but then again, sometimes a hack makes sense.
PowerShell doesn't care that you're handling the error. I filed PowerShell/PowerShell#3768 about this years ago.
Thanks for that.
One bizarre thread, a lively discussion, with an agreement from the PowerShell-committe throughout the course of a few month back in 2017.
Almost implemented in 2019, accepted by the committee once more in 2020, only to be dropped because of an overworked engineer.
Is this like this all the time? asking as you've been 'around the block' more than me.
I wonder if there are updates on this topic, but as it is a pretty complex one to implement, I doubt...