Prerequisites
Steps to reproduce
Note: Thread jobs (Start-ThreadJob) are not affected (although for them too it must be manually ensured that the job is in the Running state). Curiously, though, the technologically closely related ForEach-Object -AsJob -Parallel is affected too.
Debug-Job requires a job to be in the Running (or AtBreakPoint) state in order for debugger invocation to succeed.
- On startup, background jobs (
Start-Job) report Running earlier than expected, causing Debug-Job to fail.
$jb = Start-Job {
while ($true) { Start-Sleep -Milliseconds 100 }
}
try {
Write-Verbose -Verbose 'Waiting for job to be in the ''Running'' state...'
while ($jb.State -notin 'Running') { Start-Sleep -Milliseconds 100 }
# If you enable this, the call works.
# Start-Sleep -Milliseconds 500
Write-Verbose -Verbose 'Starting debugging...'
$jb | Debug-Job
}
finally {
if ($jb) { $jb | Remove-Job -Force }
}
Expected behavior
The debugger should be entered.
Actual behavior
Debug-Job fails with the following error:
Debug-Job: /Users/jdoe/script.ps1:10
Line |
274 | $jb | Debug-Job
| ~~~~~~~~~
| The provided job and all child jobs were examined but no jobs were found that could be debugged. In order to debug a job or child job the job must support debugging and
| also be in a running state.
Note that if you introduce an artificial delay (uncomment the Start-Sleep statement in the code), things work as expected.
Error details
Exception :
Type : System.Management.Automation.PSInvalidOperationException
ErrorRecord :
Exception :
Type : System.Management.Automation.ParentContainsErrorRecordException
Message : The provided job and all child jobs were examined but no jobs were found that could be debugged. In order to debug a job or child job the job must support
debugging and also be in a running state.
HResult : -2146233087
CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : InvalidOperation
TargetSite :
Name : ThrowTerminatingError
DeclaringType : System.Management.Automation.MshCommandRuntime, System.Management.Automation, Version=7.5.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35
MemberType : Method
Module : System.Management.Automation.dll
Message : The provided job and all child jobs were examined but no jobs were found that could be debugged. In order to debug a job or child job the job must support
debugging and also be in a running state.
Source : System.Management.Automation
HResult : -2146233079
StackTrace :
at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
TargetObject : Microsoft.PowerShell.Commands.DebugJobCommand
CategoryInfo : InvalidOperation: (Microsoft.PowerShel…nds.DebugJobCommand:DebugJobCommand) [Debug-Job], PSInvalidOperationException
FullyQualifiedErrorId : DebugJobNoDebuggableJobsFound,Microsoft.PowerShell.Commands.DebugJobCommand
InvocationInfo :
MyCommand : Debug-Job
ScriptLineNumber : 274
OffsetInLine : 9
HistoryId : 2
ScriptName : /Users/jdoe/script.ps1
Line : $jb | Debug-Job
Statement : Debug-Job
PositionMessage : At /Users/jdoe/script.ps1:10 char:9
+ $jb | Debug-Job
+ ~~~~~~~~~
PSScriptRoot : /Users/jdoe
PSCommandPath : /Users/jdoe/script.ps1
InvocationName : Debug-Job
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, /Users/jdoe/script.ps1: line 10
at <ScriptBlock>, <No file>: line 1
Environment data
PowerShell 7.5.0-preview.1
Visuals
No response
Prerequisites
Steps to reproduce
Note: Thread jobs (
Start-ThreadJob) are not affected (although for them too it must be manually ensured that the job is in theRunningstate). Curiously, though, the technologically closely relatedForEach-Object -AsJob -Parallelis affected too.Debug-Jobrequires a job to be in theRunning(orAtBreakPoint) state in order for debugger invocation to succeed.Start-Job) reportRunningearlier than expected, causingDebug-Jobto fail.Expected behavior
The debugger should be entered.Actual behavior
Debug-Jobfails with the following error:Note that if you introduce an artificial delay (uncomment the
Start-Sleepstatement in the code), things work as expected.Error details
Environment data
Visuals
No response