Skip to content

Error hidden when anonymous command uses WriteError #12727

@SeeminglyScience

Description

@SeeminglyScience

Steps to reproduce

Paste into console (Error record arguments don't matter):

[CmdletBinding()] param() end {
$PSCmdlet.WriteError([Management.Automation.ErrorRecord]::new([Exception]::new(), '', 0, '')) }

Expected behavior

Exception of type 'System.Exception' was thrown.

Actual behavior

Nothing is shown. When calling $Error[0], this is shown:

Get-Command:
Line |
 201 |  … if ($myinv.MyCommand -and (Get-Command -Name $myinv.MyCommand -ErrorA …
     |                                                 ~~~~~~~~~~~~~~~~
     | Cannot validate argument on parameter 'Name'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a collection that does not contain any null values and then try the command again.

Stringification probably shouldn't be relied on here, and $myinv.MyCommand.Name should be used instead.

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.0-preview.2
PSEdition                      Core
GitCommitId                    7.1.0-preview.2
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

Labels

Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtime

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions