-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Open
Labels
Needs-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
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-Jobrequires a job to be in theRunning(orAtBreakPoint) state in order for debugger invocation to succeed.- On startup, background jobs (
Start-Job) reportRunningearlier than expected, causingDebug-Jobto 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 1Environment data
PowerShell 7.5.0-preview.1Visuals
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Needs-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.