Skip to content

ErrorRecord.InvocationInfo.Statement property doesn't report full statement for command syntax / invalid-argument errors #20638

@mklement0

Description

@mklement0

Prerequisites

Steps to reproduce

The new-in-7.4 ErrorRecord.InvocationInfo.Statement property is designed to report the whole statement that triggered the error (possibly spanning multiple lines).

This doesn't work when the error was triggered by a command syntax error or by a parameter having been passed an invalid argument (in other words: the problem seems related to the parameter binder reporting the error):

try {
  Get-Item -NoSuchParameter -LiteralPath .
}
catch {
  '[' + $_.InvocationInfo.Statement + ']'
}

Expected behavior

[Get-Item -NoSuchParameter -LiteralPath .]

Actual behavior

[-NoSuchParameter]

That is, only the offending parameter is reported.

This applies both to unrecognized parameters and known parameters having been given no argument.
If a known parameter is given an invalid argument, only that argument is reported.

Error details

No response

Environment data

PowerShell 7.4.0-rc.1

Visuals

No response

Metadata

Metadata

Assignees

Labels

Needs-TriageThe issue is new and needs to be triaged by a work group.WG-Enginecore PowerShell engine, interpreter, and runtimeWG-NeedsReviewNeeds a review by the labeled Working Group

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions