Skip to content

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

@mklement0

Description

@mklement0

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.Object

Expected 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

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions