Setting `MergeUnclaimedPreviousCommandResults` without `MergeMyResults` throws ScriptCallDepthException
See original GitHub issueSteps 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:
- Created 3 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also would be great to expand the docs on
MergeUnclaimedPreviousCommandResults
, not very intuitive when trying to understand what it does exactly.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.