question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting `MergeUnclaimedPreviousCommandResults` without `MergeMyResults` throws ScriptCallDepthException

See original GitHub issue

Steps to reproduce

using namespace System.Management.Automation.Runspaces

$ps = $res = $null
try {
    $ps = [powershell]::Create()
    $null = $ps.AddScript("Write-Error 'test'")
    $cmd = [Command]::new(
        'process { Write-Error -ErrorRecord $_ }',
        <# isScript: #> $true)

    # Works if you uncomment this.
    # $cmd.MergeMyResults('All', 'Output')

    $cmd.MergeUnclaimedPreviousCommandResults = 'Error, Output'
    $null = $ps.Commands.AddCommand($cmd)
    $res = $ps.Invoke()
} finally {
    ($ps)?.Dispose()
}

$res

Expected behavior

No output, and does not throw ScriptCallDepthException.

Actual behavior

After ~10 minutes it throws ScriptCallDepthException.

Exception             :
    Type           : System.Management.Automation.MethodInvocationException
    ErrorRecord    :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Exception calling "Invoke" with "0" argument(s): "The script failed due to call depth overflow."
            HResult : -2146233087
        CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : ScriptCallDepthException
        InvocationInfo        :
            ScriptLineNumber : 9
            OffsetInLine     : 5
            HistoryId        : -1
            Line             :     $res = $ps.Invoke()

            PositionMessage  : At line:9 char:5
                               +     $res = $ps.Invoke()
                               +     ~~~~~~~~~~~~~~~~~~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 9
    TargetSite     :
        Name          : CheckActionPreference
        DeclaringType : System.Management.Automation.ExceptionHandlingOps, System.Management.Automation, Version=7.1.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    StackTrace     :
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
    Message        : Exception calling "Invoke" with "0" argument(s): "The script failed due to call depth overflow."
    Data           : System.Collections.ListDictionaryInternal
    InnerException :
        Type        : System.Management.Automation.ScriptCallDepthException
        ErrorRecord :
            Exception             :
                Type    : System.Management.Automation.ParentContainsErrorRecordException
                Message : The script failed due to call depth overflow.
                HResult : -2146233087
            CategoryInfo          : InvalidOperation: (0:Int32) [], ParentContainsErrorRecordException
            FullyQualifiedErrorId : CallDepthOverflow
        TargetSite  :
            Name          : Invoke
            DeclaringType : System.Management.Automation.Runspaces.PipelineBase, System.Management.Automation, Version=7.1.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35
            MemberType    : Method
            Module        : System.Management.Automation.dll
        StackTrace  :
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output,
PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output,
PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings
settings)
   at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
   at CallSite.Target(Closure , CallSite , Object )
        Message     : The script failed due to call depth overflow.
        Source      : System.Management.Automation
        HResult     : -2146233087
    Source         : System.Management.Automation
    HResult        : -2146233087
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : ScriptCallDepthException
InvocationInfo        :
    ScriptLineNumber : 9
    OffsetInLine     : 5
    HistoryId        : -1
    Line             :     $res = $ps.Invoke()

    PositionMessage  : At line:9 char:5
                       +     $res = $ps.Invoke()
                       +     ~~~~~~~~~~~~~~~~~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 9

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.0
PSEdition                      Core
GitCommitId                    7.1.0
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

Notes

Credit to @jborean93 for finding this one. Seems like the error pipe is being set to the same pipe as input.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jborean93commented, Dec 8, 2020

Also would be great to expand the docs on MergeUnclaimedPreviousCommandResults, not very intuitive when trying to understand what it does exactly.

0reactions
SeeminglySciencecommented, Feb 18, 2022

The Engine WG reviewed this today. We agree the bug this is a bug that should be fixed and will mark it as up for grabs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found