-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Update Get-Error to not modify the original $Error object #11125
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
|
CodeFactor issue is by-design |
vexx32
left a comment
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.
Looks good! Minor non-blocking comments only.
Nicely done! 😊
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Get-Error.cs
Outdated
Show resolved
Hide resolved
| try { | ||
| 1 / 0 | ||
| } | ||
| catch { | ||
| } |
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.
I know it doesn't really matter, but is there a reason you didn't just use Write-Error for this purpose? 😄
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.
Didn't consider that and this was the first thing I thought of. At least now it's consistent within the test script :)
Although I also learned later that you can just write to $Error anyways.
…-Error.cs Co-Authored-By: Joel Sallow (/u/ta11ow) <32407840+vexx32@users.noreply.github.com>
|
🎉 Handy links: |
PR Summary
Get-Errorcurrently modifies the original $Error object specifically the pstypenames. Fix is to use an overload when constructing the PSObject to copy it.PR Context
Fix #11122
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.