Skip to content
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

"Exception thrown from prompt block" even when the exception is handled within the block #68

Open
Lockszmith-GH opened this issue Nov 11, 2021 · 5 comments

Comments

@Lockszmith-GH
Copy link

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.
@Lockszmith-GH
Copy link
Author

Thought it might do with capturing of the error stream, but this caused the same behavior:

$Prompt.Add( { $(try{throw "error"}catch{} *>&1)} )

@Jaykul
Copy link
Owner

Jaykul commented Dec 17, 2021

You'll have to Set-PowerLinePrompt -HideErrors

PowerShell doesn't care that you're handling the error. I filed PowerShell/PowerShell#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).

@Lockszmith-GH
Copy link
Author

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.

@Lockszmith-GH
Copy link
Author

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.

@apetitjean
Copy link

I wonder if there are updates on this topic, but as it is a pretty complex one to implement, I doubt...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants