Skip to content

Proxy command should only invoke $steppablePipeline.Clean() when the variable is defined #16826

@SeeminglyScience

Description

@SeeminglyScience

Prerequisites

Steps to reproduce

$function:ProxyGci = [scriptblock]::Create(
    [Management.Automation.ProxyCommand]::Create(
        (Get-Command Get-ChildItem)))

ProxyGci -Attributes

Expected behavior

ProxyGci: Missing an argument for parameter 'Attributes'. Specify a parameter of type 'System.Management.Automation.FlagsExpression`1[System.IO.FileAttributes]' and try again.

Actual behavior

InvalidOperation:
Line |
 101 |      $steppablePipeline.Clean()
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~
     | You cannot call a method on a null-valued expression.
ProxyGci: Missing an argument for parameter 'Attributes'. Specify a parameter of type 'System.Management.Automation.FlagsExpression`1[System.IO.FileAttributes]' and try again.

Error details

Exception             : 
    Type              : System.Management.Automation.ParameterBindingException
    Message           : Missing an argument for parameter 'Attributes'. Specify a parameter of type 'System.Management.Automation.FlagsExpression`1[System.IO.FileAttributes]' and try again.
    ParameterName     : Attributes
    ParameterType     : System.Management.Automation.FlagsExpression[System.IO.FileAttributes]
    ErrorId           : MissingArgument
    Line              : 1
    Offset            : 10
    CommandInvocation : 
        MyCommand        : ProxyGci
        ScriptLineNumber : 1
        OffsetInLine     : 1
        HistoryId        : 4
        Line             : proxygci -Attributes
        PositionMessage  : At line:1 char:1
                           + proxygci -Attributes
                           + ~~~~~~~~~~~~~~~~~~~~
        InvocationName   : proxygci
        PipelineLength   : 1
        PipelinePosition : 1
    ErrorRecord       : 
        Exception             : 
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Missing an argument for parameter 'Attributes'. Specify a parameter of type 'System.Management.Automation.FlagsExpression`1[System.IO.FileAttributes]' and try again.
            HResult : -2146233087
        CategoryInfo          : InvalidArgument: (:) [ProxyGci], ParentContainsErrorRecordException
        FullyQualifiedErrorId : MissingArgument,ProxyGci
        InvocationInfo        : 
            MyCommand        : ProxyGci
            ScriptLineNumber : 1
            OffsetInLine     : 10
            HistoryId        : 4
            Line             : proxygci -Attributes
            PositionMessage  : At line:1 char:10
                               + proxygci -Attributes
                               +          ~~~~~~~~~~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    TargetSite        : 
        Name          : ReparseUnboundArguments
        DeclaringType : System.Management.Automation.ParameterBinderController, System.Management.Automation, Version=7.3.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Data              : System.Collections.ListDictionaryInternal
    Source            : System.Management.Automation
    HResult           : -2146233087
    StackTrace        : 
   at System.Management.Automation.ParameterBinderController.ReparseUnboundArguments()
   at System.Management.Automation.CmdletParameterBinderController.HandleCommandLineDynamicParameters(ParameterBindingException& outgoingBindingException)
   at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 arguments)
   at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)
   at System.Management.Automation.CommandProcessor.BindCommandLineParameters()
   at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues)
   at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
   at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
--- End of stack trace from previous location ---
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
   at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
   at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
CategoryInfo          : InvalidArgument: (:) [ProxyGci], ParameterBindingException
FullyQualifiedErrorId : MissingArgument,ProxyGci
InvocationInfo        : 
    MyCommand        : ProxyGci
    ScriptLineNumber : 1
    OffsetInLine     : 10
    HistoryId        : 4
    Line             : proxygci -Attributes
    PositionMessage  : At line:1 char:10
                       + proxygci -Attributes
                       +          ~~~~~~~~~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

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

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions