Skip to content

Update Get-Error to not modify the original $Error object - #11125

Merged
Ilya (iSazonov) merged 2 commits into
PowerShell:masterfrom
SteveL-MSFT:get-error-ets
Nov 21, 2019
Merged

Ilya (iSazonov) merged 2 commits into
PowerShell:masterfrom
SteveL-MSFT:get-error-ets

Conversation

@SteveL-MSFT

@SteveL-MSFT Steve Lee (SteveL-MSFT) commented Nov 19, 2019 •

Copy link
Copy Markdown
Member

PR Summary

Get-Error currently 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

@SteveL-MSFT

Copy link
Copy Markdown
Member Author

CodeFactor issue is by-design

Copy link
Copy Markdown
Collaborator

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! 😊

Comment on lines +113 to +117
try {
1 / 0
}
catch {
}

Copy link
Copy Markdown
Collaborator

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? 😄

Copy link
Copy Markdown
Member Author

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.

@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Nov 20, 2019
@iSazonov Ilya (iSazonov) added this to the 7.0.0-preview.6 milestone Nov 20, 2019
…-Error.cs

Co-Authored-By: Joel Sallow (/u/ta11ow) <32407840+vexx32@users.noreply.github.com>
@ghost

Copy link
Copy Markdown

🎉v7.0.0-rc.2 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get-Error unexpectedly modifies the ETS type names of the ErrorRecord instances it processes in place

4 participants