-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix ErrorActionPreference not being respected from throw site when reset in finally block #15833
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
Conversation
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
6407f94 to
fe52ad8
Compare
| try | ||
| { | ||
| $oldEAP = $ErrorActionPreference | ||
| $ErrorActionPreference = 'Stop' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test name says nothing about "Stop". Make sense to have tests for all possible ErrorActionPreference values?
|
So looking through the behaviour here, it looks like something deeper is still happening in an unexpected way. Compare: > get-process -banana; write-host 'hello'
Get-Process: A parameter cannot be found that matches parameter name 'banana'.
hello> try { get-process -banana; write-host 'hello' } catch { }
# No output hereParameter binding seems to create a non-terminating error that can be caught... |
|
Going to mark this for Working Group review again |
|
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 15 days. It will be closed if no further activity occurs within 10 days of this comment. |
PR Summary
Fixes #15726.
When an error is thrown due to
$ErrorActionPreference = 'Stop', we now mark it at the first opportunity to prevent having the action preference re-interpreted at a later stage (so that a finally block changing the value won't cause the error to be quietly downgraded).Labelled as a breaking change because the existing behaviour is observable, but I think is a bucket-3 corner case behaviour that users would experience as a bug. Of note is that ordinary errors written with the
WriteError()API will exhibit the correct behaviour, and this change just ensures that all other errors behave the same way.PR Context
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).