Skip to content

VSCode crashes with errior in PSReadLine #2074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
doctordns opened this issue Dec 24, 2020 · 10 comments
Closed

VSCode crashes with errior in PSReadLine #2074

doctordns opened this issue Dec 24, 2020 · 10 comments
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation.

Comments

@doctordns
Copy link

doctordns commented Dec 24, 2020

Using VS Code with PowerShell 7.1 Got this error:

PS C:\Foo> CATR C:\Users\Administrator.RESKIT\DOCUMENTS\POWERSHELL\powershell.config.json
CATR: The term 'CATR' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Suggestion [4,General]: The most similar commands are: cat, cp, cd, dir, copy, clc, cli, clp, clv, cpi.
PS C:\Foo> CAT C:\Users\Administrator.RESKIT\DOCUMENTS\POWERSHELL\powershell.config.json
{"ExperimentalFeatures":["PSCommandNotFoundSuggestion","PSCultureInvariantReplaceOperator"]}
PS C:\Foo> Ge
Oops, something went wrong.
Please report this bug with ALL the details below, including both the 'Environment' and 'Exception' sections.
Please report on GitHub: https://github.com/PowerShell/PSReadLine/issues/new?template=Bug_Report.md
Thank you!

### Environment
PSReadLine: 2.1.0
PowerShell: 7.1.0
OS: Microsoft Windows 10.0.20270
BufferWidth: 129
BufferHeight: 15

Last 200 Keys

 E C U T I O N G Tab Backspace Tab Enter
 D I R Spacebar $ P S H O M E Enter
 UpArrow Backspace Backspace Backspace Backspace Backspace Backspace H O M S Backspace E Enter
 UpArrow \ D O C U Tab Ctrl+z M E N T S \ P O W E R S H E L L Enter
 UpArrow \ M I C R O S O F T Tab Tab Tab Tab Tab Tab Tab Tab Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace P Tab Enter
 UpArrow Home Home C A T Delete Delete Enter
 UpArrow Home RightArrow RightArrow RightArrow Delete Enter
 G e t - E x p e r i m e n t a l F e a t u r e Spacebar - N a m e Spacebar * Spacebar | Spacebar Enter
 Spacebar Spacebar S e l e c t - O b j e c t Spacebar - F i r s t Spacebar 1 Spacebar | Enter
 Spacebar Spacebar Spacebar Spacebar E n a b l


### Exception

System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension. (Parameter 'top')
Actual value was 15.
   at System.ConsolePal.SetCursorPosition(Int32 left, Int32 top)
   at Microsoft.PowerShell.PSConsoleReadLine.CalculateWhereAndWhatToRender(Boolean cursorMovedToInitialPos, RenderData renderData, LineInfoForRendering& lineInfoForRendering)
   at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
   at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
   at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
   at Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable`1 key, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(PSKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken)

As requested - this is a report.

Environment

Environment

PSReadLine: 2.1.0
PowerShell: 7.1.0
OS: Microsoft Windows 10.0.20270
BufferWidth: 129
BufferHeight: 15

Exception report

Exception

System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension. (Parameter 'top')
Actual value was 15.
   at System.ConsolePal.SetCursorPosition(Int32 left, Int32 top)
   at Microsoft.PowerShell.PSConsoleReadLine.CalculateWhereAndWhatToRender(Boolean cursorMovedToInitialPos, RenderData renderData, LineInfoForRendering& lineInfoForRendering)
   at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
   at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
   at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
   at Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable`1 key, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(PSKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken)

Steps to reproduce

working in VS COde??

Expected behavior

no error!

Actual behavior

VS Code terminal seems to error.

@ghost ghost added the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Dec 24, 2020
@champ9000
Copy link

have you edited your MAX_PATH to allow paths over the default 256 characters? If not, you can go to the registry and under the following path, Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem you should see the entry called LongPathsEnabled double click that entry and replace the 0 to a 1 and that should clear out your issue.

@daxian-dbw
Copy link
Member

@doctordns The "Last 200 keys" shows the last input is something like the following snippet,

Get-ExperimentalFeature -Name * |
  Select-Object -First 1 |
    Enabl

but the screen content you shared shows the exception happened at

PS C:\Foo> Ge
Oops, something went wrong.
...

Did you miss any screen content?

Could you please share a repro for this issue? That would be very helpful to our investigation. Thank you in advance!

@daxian-dbw daxian-dbw added Issue-Bug It either shouldn't be doing this or needs an investigation. and removed Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. labels Jan 5, 2021
@doctordns
Copy link
Author

I can not find dupicate it at will, but I do see it a lot.

As for the truncation - this is an irregular issue with VS Code. It regularly eats output. I run a script and the output gets munged.

@divillysausages
Copy link

I have this same issue recently running Jest tests with the Jest Runner extension.

LongPathsEnabled in Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem was already set to 1.

Jest is set to "jest": "^25.5.4" in package.json.

It was previously working, and I haven't updated since, so I'm not sure what triggered the behaviour

Exception:

System.ArgumentOutOfRangeException: The value must be 
greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: left
Actual value was -1.
   at System.Console.SetCursorPosition(Int32 left, Int32 top)
   at Microsoft.PowerShell.Internal.VirtualTerminal.set_CursorLeft(Int32 value)
   at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)       
   at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
   at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
   at Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable`1 key, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)

@divillysausages
Copy link

Manually writing out tests for jest seem to trigger this when it reaches a quote character " or '

E.g. writing

npm test -- -t "Foo"

Will trigger the exception when you type the character " before Foo

@daxian-dbw
Copy link
Member

@divillysausages What version of PSReadLine are you using? Can you run the following script to collect some environment data?

& {
    $hostName = $Host.Name
    if ($hostName -eq "ConsoleHost" -and (Get-Command Get-CimInstance -ErrorAction SilentlyContinue)) {
        $id = $PID
        $inWindowsTerminal = $false
        while ($true) {
            $p = Get-CimInstance -ClassName Win32_Process -Filter "ProcessId Like $id"
            if (!$p -or !$p.Name) { break }
            if ($p.Name -eq "WindowsTerminal.exe") { $inWindowsTerminal = $true; break }
            $id = $p.ParentProcessId
        }
        if ($inWindowsTerminal) { $hostName += " (Windows Terminal)" }
    }

    "`nPS version: $($PSVersionTable.PSVersion)"
    $m = Get-Module PSReadline
    $v = $m.Version; $pre = $m.PrivateData.PSData.Prerelease
    if ($pre) { $v = "$v-$pre" }
    "PSReadline version: $v"
    if ($IsLinux -or $IsMacOS) {
        "os: $(uname -a)"
    } else {
        "os: $((dir $env:SystemRoot\System32\cmd.exe).VersionInfo.FileVersion)"
    }
    "PS file version: $($name = if ($PSVersionTable.PSEdition -eq "Core") { "pwsh.dll" } else { "powershell.exe" }; (dir $pshome\$name).VersionInfo.FileVersion)"
    "HostName: $hostName"
    "BufferWidth: $([console]::BufferWidth)"
    "BufferHeight: $([console]::BufferHeight)`n"
}

@divillysausages
Copy link

Hi @daxian-dbw

Output:

PS version: 5.1.19041.610
PSReadline version: 2.0.0-beta2
os: 10.0.19041.1 (WinBuild.160101.0800)
PS file version: 10.0.19041.1 (WinBuild.160101.0800)
HostName: ConsoleHost
BufferWidth: 173
BufferHeight: 46

This is from the powershell console inside VSCode, if that wasn't clear.

I'll write my tests, and the Jest Runner plugin will give me a little Run | Debug link above it to run just that test. Most of the time, clicking Run will have no issue. Then sometimes I'll hit it and it'll give me the error, but still run the test. Then sometimes it'll run it and stop. Normally though, running jest tests runs in it's own jest console, so I'm not quite sure why it's triggering powershell

It's rare enough that I haven't been able to figure out the exact steps to reproduce it, unfortunately :(

@daxian-dbw
Copy link
Member

@divillysausages Thanks! The 2.0.0-beta2 version of PSReadLine is very old, and thus the issue you were seeing is likely already fixed. Please upgrade to the 2.1.0 version of PSReadLine from PowerShell Gallery. See the upgrading section for instructions. Let us know by opening a new issue, if you run into the same issue with the latest version.

@daxian-dbw
Copy link
Member

For the original report, it is a true issue that I saw from a few other reports (CalculateWhereAndWhatToRender being in the call stack), but I'm not able to investigate without a repro. So I will close this issue for now.

@daxian-dbw
Copy link
Member

Mark this issue as a duplicate of #2298

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation.
Projects
None yet
Development

No branches or pull requests

4 participants