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.

Piping ssh output to cmdlet with debug breakpoint crashes PowerShell

See original GitHub issue

Prerequisites

Steps to reproduce

Piping output from ssh (more specifically cating some syslogs) into a cmdlet with a breakpoint set causes PowerShell to crash as soon as the breakpoint is hit.

I hit this while trying to debug my ConvertFrom-RegEx module, but given that I have a 100% crash-rate no matter where the breakpoint is I don’t think this is something to do with my code. (Even then, the debugger/pwsh executable crashing isn’t ideal.)

Storing ssh output into a variable and piping that variable into the cmdlet with breakpoints works normally. Perhaps ssh is preventing the debugger from calling ReadKey()?

Expected behavior

PS> pushd $HOME\source\repos
PS> ipmo .\ConvertFrom-RegEx\ConvertFrom-RegEx # repo hmmwhatsthisdo/ConvertFrom-RegEx, commit f18a0a46
PS> Set-PSBreakpoint -Script .\ConvertFrom-RegEx\ConvertFrom-RegEx\Public\ConvertFrom-RegEx.ps1 -Line 135 
PS> ssh $remoteuser@$remoteip -i $HOME\.ssh\$remoteuser-id_rsa cat /var/log/syslog | ConvertFrom-RegEx -Pattern '^(?<month>\S+)'
# [PowerShell hits debugger breakpoint]

Actual behavior

Debugger crashes upon hitting breakpoint

Error details

An error has occurred that was not properly handled. Additional information is shown below. The PowerShell process will exit.
Unhandled exception. System.InvalidOperationException: Cannot read keys when either application does not have a console or when console input has been redirected. Try Console.Read.
   at System.ConsolePal.ReadKey(Boolean intercept)
   at Microsoft.PowerShell.PSConsoleReadLine.ReadOneOrMoreKeys()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadKeyThreadProc()
   at System.Threading.Thread.StartHelper.Callback(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Thread.StartCallback()

Environment data

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.6
PSEdition                      Core
GitCommitId                    7.2.6
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

image

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
dkaszewscommented, Sep 18, 2022

there are several more-graceful ways to handle the situation than crashing the PowerShell process

@hmmwhatsthisdo Fair point, even if some process locks input, debugger could try to detect it and show an error “Unable to debug interactive process” instead.

0reactions
PaulHigincommented, Nov 14, 2022

Removing the WG-Remoting tag because this does not involve PowerShell remoting, and appears to be a bug in PowerShell during command line debugging.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set-PSBreakpoint (Microsoft.PowerShell.Utility)
This example creates a command breakpoint on the Increment function in the Sample.ps1 cmdlet. The script stops executing immediately before each call to...
Read more >
Cannot debug PowerShell scripts in Visual Studio Code
4 Answers. To solve this problem, you can try to restart your current PowerShell session by: Opening the command pallet ( command +...
Read more >
Gdb remote debugging vscode. The gdb we are using has to ...
Can view source, set breakpoints on the target just fine. json, ... When debugging a C project in VSCode with GDB, the output...
Read more >
Debug with SSH
The SSH command is formatted as follows. Replace {harness pat} with your token that has pipeline execution permissions.
Read more >
Enable-PSBreakpoint (Microsoft.PowerShell.Utility)
Enable-PSBreakpoint is one of several cmdlets designed for debugging PowerShell scripts. ... This example enables all breakpoints in the current session.
Read more >

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