There may be a bug in unreleased code that throws a PSReadLine exception under certain conditions #17397

Open
opened 2026-01-31 05:41:15 +00:00 by claunia · 0 comments
Owner

Originally created by @YanceyChiew on GitHub (May 4, 2022).

Windows Terminal version

0.0.1.0 (dev version, not before 1.13.10984 preview or after pr #13026)

Windows build number

10.0.22000.652

Other Software

PSReadLine 2.1.0, 2.2.5
Powershell Core 7.2.3, 7.3.0-preview.3

PSReadLine: 2.0.0
Windows PowerShell: 5.1.22000.652

Reproduced in the above versions, other versions have not been tested.

Steps to reproduce

1 Set Windows Terminal Dev as the default terminal
2 Keep the launch size in the Startup settings as 120 * 30.
3 Then open the terminal by opening powershell.

Expected Behavior

Open powershell normally.

Actual Behavior

When the first keystroke is made, powershell throws the following exception:

PS C:\>
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.yaml
Thank you!

### Environment
PSReadLine: 2.2.5
PowerShell: 7.2.3
OS: Microsoft Windows 10.0.22000
BufferWidth: 120
BufferHeight: 30

Last 1 Keys:

 a

### Exception

System.IO.IOException: 数据无效
   at System.ConsolePal.SetCursorPosition(Int32 left, Int32 top)
   at System.Console.SetCursorPosition(Int32 left, Int32 top)
   at Microsoft.PowerShell.Internal.VirtualTerminal.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.Render()
   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, Nullable`1 lastRunStatus)

If the keystroke is enter, and the input timing is not too early, the exception is deferred until another non-enter keystroke has been made.

Last 6 Keys:

 Enter
 Enter
 Enter
 Enter
 Enter
 Escape

### Exception
...

After the exception is thrown, powershell works fine.

There are three points worth noting:

  • If you open powershell directly from the terminal, there is no such exception.
  • If any item in launch size is changed so that it is not exactly 120*30, there is no such exception.
  • There is no such exception in Microsoft.WindowsTerminalPreview_Win11_1.13.10984.0, this exception may be unique to the debug version, or introduced by subsequent commits.

Although the exception is thrown by PSReadLine, it does not occur in other versions of windows terminal with the same settings and opening methods.

I didn't locate the problem code and don't know if anyone else can reproduce this exception.

Originally created by @YanceyChiew on GitHub (May 4, 2022). ### Windows Terminal version 0.0.1.0 (dev version, not before 1.13.10984 preview or after pr #13026) ### Windows build number 10.0.22000.652 ### Other Software PSReadLine 2.1.0, 2.2.5 Powershell Core 7.2.3, 7.3.0-preview.3 PSReadLine: 2.0.0 Windows PowerShell: 5.1.22000.652 _Reproduced in the above versions, other versions have not been tested._ ### Steps to reproduce 1 Set Windows Terminal Dev as the default terminal 2 Keep the launch size in the Startup settings as 120 * 30. 3 Then open the terminal by opening powershell. ### Expected Behavior Open powershell normally. ### Actual Behavior When the first keystroke is made, powershell throws the following exception: ```pwsh PS C:\> 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.yaml Thank you! ### Environment PSReadLine: 2.2.5 PowerShell: 7.2.3 OS: Microsoft Windows 10.0.22000 BufferWidth: 120 BufferHeight: 30 Last 1 Keys: a ### Exception System.IO.IOException: 数据无效。 at System.ConsolePal.SetCursorPosition(Int32 left, Int32 top) at System.Console.SetCursorPosition(Int32 left, Int32 top) at Microsoft.PowerShell.Internal.VirtualTerminal.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.Render() 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, Nullable`1 lastRunStatus) ``` If the keystroke is <kbd>enter</kbd>, and the input timing is not too early, the exception is deferred until another non-<kbd>enter</kbd> keystroke has been made. ```pwsh Last 6 Keys: Enter Enter Enter Enter Enter Escape ### Exception ... ``` After the exception is thrown, powershell works fine. There are three points worth noting: - If you open powershell directly from the terminal, there is no such exception. - If any item in launch size is changed so that it is not exactly 120*30, there is no such exception. - There is no such exception in [Microsoft.WindowsTerminalPreview_Win11_1.13.10984.0](https://github.com/microsoft/terminal/releases/download/v1.13.10983.0/Microsoft.WindowsTerminalPreview_Win11_1.13.10984.0_8wekyb3d8bbwe.msixbundle), this exception may be unique to the debug version, or introduced by subsequent commits. Although the exception is thrown by PSReadLine, it does not occur in other versions of windows terminal with the same settings and opening methods. _I didn't locate the problem code and don't know if anyone else can reproduce this exception._
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#17397