-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Description
The handy new Get-Error cmdlet implements its pretty-printing by replacing the System.Management.Automation.ErrorRecord type name in the ETS type-name array with PSExtendedError.
Unfortunately, it does this on the originals in the $Error collection, resulting in inadvertent modification that makes these instances print differently with implicit output (e.g., $Error[0]) afterwards.
Steps to reproduce
# Provoke a an error.
try { 1 / 0 } catch {}
$Error[0].pstypenames | Should -Be System.Management.Automation.ErrorRecord, System.Object
# Run Get-Error, which accidentally modifies .pstypenames of the most recent error.
$null = Get-Error
# Repeating the test shows the modified .pstypenames
$Error[0].pstypenames | Should -Be System.Management.Automation.ErrorRecord, System.ObjectExpected behavior
Both tests should succeed.
Actual behavior
The 2nd test fails:
Expected @('System.Management.Automation.ErrorRecord', 'System.Object'), but got @('PSExtendedError', 'System.Object').
That is, $Error[0]'s .pstypename property was accidentally modified.
Environment data
PowerShell Core 7.0.0-preview.5
Metadata
Metadata
Assignees
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module