Skip to content

[Regression] Get-Error exception in StrictMode on latest daily builds of PS #18719

@kborowinski

Description

@kborowinski

Prerequisites

Steps to reproduce

Get-Error command throws an exception when running in StrictMode on latest daily builds of PS:
(On PS 7.3.0 GA it works as expected)

[CMD][Bukem@ATLANTIS] > pwsh -nop
PowerShell 7.3.0-preview.3-505-g4c580f7330cae70f70b820dc282f5e81a4b96c31
PS C:\> Set-StrictMode -Version Latest
PS C:\> 1/0
RuntimeException: Attempted to divide by zero.
PS C:\> Get-Error

Exception             :
    Type        : System.Management.Automation.RuntimeException
    ErrorRecord :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : The variable '$commandPrefix' cannot be retrieved because it has not been set.
            HResult : -2146233087
        TargetObject          : commandPrefix
        CategoryInfo          : InvalidOperation: (commandPrefix:String) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : VariableIsUndefined
        InvocationInfo        :
            ScriptLineNumber : 56
            OffsetInLine     : 41
            HistoryId        : -1
            Line             : if ($commandPrefix)

            PositionMessage  : At line:56 char:41
                               +                                     if ($commandPrefix)
                               +                                         ~~~~~~~~~~~~~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 56
                                at <ScriptBlock>, <No file>: line 1
    TargetSite  :
        Name          : CheckActionPreference
        DeclaringType : System.Management.Automation.ExceptionHandlingOps, System.Management.Automation, Version=7.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message     : The variable '$commandPrefix' cannot be retrieved because it has not been set.
    Data        : System.Collections.ListDictionaryInternal
    Source      : System.Management.Automation
    HResult     : -2146233087
    StackTrace  :
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\runtime\Operations\MiscOps.cs:line 1659
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\CallInstruction.Generated.cs:line 504
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\ControlFlowInstructions.cs:line 389
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\ControlFlowInstructions.cs:line 355
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame) in D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\Interpreter.cs:line 105
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0) in D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\LightLambda.Generated.cs:line 81
   at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope, Dictionary`2 functionsToDefine, List`1 variablesToDefine,
ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Object[] args) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\runtime\CompiledScriptBlock.cs:line 1209
   at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe,
InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List`1 variablesToDefine, Dictionary`2 functionsToDefine, Object[] args) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\lang\scriptblock.cs:line 980
   at System.Management.Automation.ScriptBlock.DoInvokeReturnAsIs(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Object[] args) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\lang\scriptblock.cs:line 927
   at Microsoft.PowerShell.Commands.PSPropertyExpression.GetValue(PSObject target, Boolean eatExceptions) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\FormatAndOutput\common\Utilities\Mshexpression.cs:line 317
TargetObject          : commandPrefix
CategoryInfo          : InvalidOperation: (commandPrefix:String) [], RuntimeException
FullyQualifiedErrorId : VariableIsUndefined
InvocationInfo        :
    ScriptLineNumber : 56
    OffsetInLine     : 41
    HistoryId        : -1
    Line             : if ($commandPrefix)

    PositionMessage  : At line:56 char:41
                       +                                     if ($commandPrefix)
                       +                                         ~~~~~~~~~~~~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 56
                        at <ScriptBlock>, <No file>: line 1

PS C:\>

Expected behavior

[CMD][Bukem@ATLANTIS] > pwsh -nop
PowerShell 7.3.0-preview.3-505-g4c580f7330cae70f70b820dc282f5e81a4b96c31
PS C:\> 1/0
RuntimeException: Attempted to divide by zero.
PS C:\> Get-Error

Exception             :
    Type           : System.Management.Automation.RuntimeException
    ErrorRecord    :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Attempted to divide by zero.
            HResult : -2146233087
        CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : RuntimeException
        InvocationInfo        :
            ScriptLineNumber : 1
            OffsetInLine     : 1
            HistoryId        : -1
            Line             : 1/0
            PositionMessage  : At line:1 char:1
                               + 1/0
                               + ~~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    TargetSite     :
        Name          : Divide
        DeclaringType : System.Management.Automation.IntOps, System.Management.Automation, Version=7.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message        : Attempted to divide by zero.
    Data           : System.Collections.ListDictionaryInternal
    InnerException :
        Type    : System.DivideByZeroException
        Message : Attempted to divide by zero.
        HResult : -2147352558
    Source         : System.Management.Automation
    HResult        : -2146233087
    StackTrace     :
   at System.Management.Automation.IntOps.Divide(Int32 lhs, Int32 rhs) in D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\runtime\Operations\NumericOps.cs:line 58
   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\DynamicInstructions.Generated.cs:line 166
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\ControlFlowInstructions.cs:line 355
CategoryInfo          : NotSpecified: (:) [], RuntimeException
FullyQualifiedErrorId : RuntimeException
InvocationInfo        :
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : -1
    Line             : 1/0
    PositionMessage  : At line:1 char:1
                       + 1/0
                       + ~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Actual behavior

[CMD][Bukem@ATLANTIS] > pwsh -nop
PowerShell 7.3.0-preview.3-505-g4c580f7330cae70f70b820dc282f5e81a4b96c31
PS C:\> Set-StrictMode -Version Latest
PS C:\> 1/0
RuntimeException: Attempted to divide by zero.
PS C:\> Get-Error

Exception             :
    Type        : System.Management.Automation.RuntimeException
    ErrorRecord :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : The variable '$commandPrefix' cannot be retrieved because it has not been set.
            HResult : -2146233087
        TargetObject          : commandPrefix
        CategoryInfo          : InvalidOperation: (commandPrefix:String) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : VariableIsUndefined
        InvocationInfo        :
            ScriptLineNumber : 56
            OffsetInLine     : 41
            HistoryId        : -1
            Line             : if ($commandPrefix)

            PositionMessage  : At line:56 char:41
                               +                                     if ($commandPrefix)
                               +                                         ~~~~~~~~~~~~~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 56
                                at <ScriptBlock>, <No file>: line 1
    TargetSite  :
        Name          : CheckActionPreference
        DeclaringType : System.Management.Automation.ExceptionHandlingOps, System.Management.Automation, Version=7.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message     : The variable '$commandPrefix' cannot be retrieved because it has not been set.
    Data        : System.Collections.ListDictionaryInternal
    Source      : System.Management.Automation
    HResult     : -2146233087
    StackTrace  :
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\runtime\Operations\MiscOps.cs:line 1659
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\CallInstruction.Generated.cs:line 504
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\ControlFlowInstructions.cs:line 389
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\ControlFlowInstructions.cs:line 355
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame) in D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\Interpreter.cs:line 105
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0) in D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\LightLambda.Generated.cs:line 81
   at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope, Dictionary`2 functionsToDefine, List`1 variablesToDefine,
ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Object[] args) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\runtime\CompiledScriptBlock.cs:line 1209
   at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe,
InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List`1 variablesToDefine, Dictionary`2 functionsToDefine, Object[] args) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\lang\scriptblock.cs:line 980
   at System.Management.Automation.ScriptBlock.DoInvokeReturnAsIs(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Object[] args) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\lang\scriptblock.cs:line 927
   at Microsoft.PowerShell.Commands.PSPropertyExpression.GetValue(PSObject target, Boolean eatExceptions) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\FormatAndOutput\common\Utilities\Mshexpression.cs:line 317
TargetObject          : commandPrefix
CategoryInfo          : InvalidOperation: (commandPrefix:String) [], RuntimeException
FullyQualifiedErrorId : VariableIsUndefined
InvocationInfo        :
    ScriptLineNumber : 56
    OffsetInLine     : 41
    HistoryId        : -1
    Line             : if ($commandPrefix)

    PositionMessage  : At line:56 char:41
                       +                                     if ($commandPrefix)
                       +                                         ~~~~~~~~~~~~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 56
                        at <ScriptBlock>, <No file>: line 1

Error details

Exception             :
    Type        : System.Management.Automation.RuntimeException
    ErrorRecord :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : The variable '$commandPrefix' cannot be retrieved because it has not been set.
            HResult : -2146233087
        TargetObject          : commandPrefix
        CategoryInfo          : InvalidOperation: (commandPrefix:String) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : VariableIsUndefined
        InvocationInfo        :
            ScriptLineNumber : 56
            OffsetInLine     : 41
            HistoryId        : -1
            Line             : if ($commandPrefix)

            PositionMessage  : At line:56 char:41
                               +                                     if ($commandPrefix)
                               +                                         ~~~~~~~~~~~~~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 56
                                at <ScriptBlock>, <No file>: line 1
    TargetSite  :
        Name          : CheckActionPreference
        DeclaringType : System.Management.Automation.ExceptionHandlingOps, System.Management.Automation, Version=7.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message     : The variable '$commandPrefix' cannot be retrieved because it has not been set.
    Data        : System.Collections.ListDictionaryInternal
    Source      : System.Management.Automation
    HResult     : -2146233087
    StackTrace  :
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\runtime\Operations\MiscOps.cs:line 1659
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\CallInstruction.Generated.cs:line 504
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\ControlFlowInstructions.cs:line 389
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\ControlFlowInstructions.cs:line 355
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame) in D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\Interpreter.cs:line 105
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0) in D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\interpreter\LightLambda.Generated.cs:line 81
   at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope, Dictionary`2 functionsToDefine, List`1 variablesToDefine,
ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Object[] args) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\runtime\CompiledScriptBlock.cs:line 1209
   at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe,
InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List`1 variablesToDefine, Dictionary`2 functionsToDefine, Object[] args) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\lang\scriptblock.cs:line 980
   at System.Management.Automation.ScriptBlock.DoInvokeReturnAsIs(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Object[] args) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\engine\lang\scriptblock.cs:line 927
   at Microsoft.PowerShell.Commands.PSPropertyExpression.GetValue(PSObject target, Boolean eatExceptions) in
D:\DEVELOPMENT\PowerShellCore\src\System.Management.Automation\FormatAndOutput\common\Utilities\Mshexpression.cs:line 317
TargetObject          : commandPrefix
CategoryInfo          : InvalidOperation: (commandPrefix:String) [], RuntimeException
FullyQualifiedErrorId : VariableIsUndefined
InvocationInfo        :
    ScriptLineNumber : 56
    OffsetInLine     : 41
    HistoryId        : -1
    Line             : if ($commandPrefix)

    PositionMessage  : At line:56 char:41
                       +                                     if ($commandPrefix)
                       +                                         ~~~~~~~~~~~~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 56
                        at <ScriptBlock>, <No file>: line 1

Environment data

PSVersion                      7.3.0-preview.3
PSEdition                      Core
GitCommitId                    7.3.0-preview.3-505-g4c580f7330cae70f70b820dc282f5e81a4b96c31
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions