Stable Terminal crashes when cursor reaches console end in a custom script #20713

Open
opened 2026-01-31 07:21:58 +00:00 by claunia · 0 comments
Owner

Originally created by @farag2 on GitHub (Oct 22, 2023).

Originally assigned to: @lhecker on GitHub.

Windows Terminal version

1.18.2822.0

Windows build number

10.0.22621.2428

Other Software

cls

[Console]::CursorTop = 20

function Show-Menu
{
	[CmdletBinding()]
	param
	(
		[Parameter(Mandatory = $true)]
		[array]
		$Menu,

		[Parameter(Mandatory = $true)]
		[int]
		$Default
	)

	# https://github.com/microsoft/terminal/issues/14992
	[System.Console]::BufferHeight += $Menu.Count
	$minY = [Console]::CursorTop
	$y = [Math]::Max([Math]::Min($Default, $Menu.Count), 0)

	do
	{
		[Console]::CursorTop = $minY
		[Console]::CursorLeft = 0
		$i = 0

		foreach ($item in $Menu)
		{
			if ($i -ne $y)
			{
				Write-Information -MessageData ('  {1}  ' -f ($i+1), $item) -InformationAction Continue
			}
			else
			{
				Write-Information -MessageData ('[ {1} ]' -f ($i+1), $item) -InformationAction Continue
			}

			$i++
		}

		$k = [Console]::ReadKey()
		switch ($k.Key)
		{
			"UpArrow"
			{
				if ($y -gt 0)
				{
					$y--
				}
			}
			"DownArrow"
			{
				if ($y -lt ($Menu.Count - 1))
				{
					$y++
				}
			}
			"Enter"
			{
				return $Menu[$y]
			}
		}
	}
	while ($k.Key -notin ([ConsoleKey]::Escape, [ConsoleKey]::Enter))
}

do
{
	$Choice = Show-Menu -Menu @("Yes", "No", "Warning") -Default 2

	switch ($Choice)
	{
		$Yes
		{
			continue
		}
		$No
		{
			"No"
		}
		$KeyboardArrows {}
	}
}
until ($Choice -ne "Warning")

Steps to reproduce

Run script and choose "Warning" answer as much as you can. At the end Terminal will be crashed when interactive menu reaches the console window bottom.

Expected Behavior

It should continue waiting for a right answer without crashing

Actual Behavior

Terminal is crashed.

Tested with all PowerShell versions. Pure PowerShell without Terminal has no crash. Also a Terminal Preview version has no crash too! Tested on 1.19.2682.0.

Event ID: 1025

Application: pwsh.exe
CoreCLR Version: 7.0.1123.42427
.NET Version: 7.0.11
Description: The application requested process termination through System.Environment.FailFast.
Message: The Win32 internal error "No process is on the other end of the pipe." 0xE9 occurred while getting console output buffer information. Contact Microsoft Customer Support Services.
Description: The process was terminated due to an unhandled exception.System.Management.Automation.Host.HostException: The Win32 internal error "No process is on the other end of the pipe." 0xE9 occurred while getting console output buffer information. Contact Microsoft Customer Support Services.
 ---> System.ComponentModel.Win32Exception (233): No process is on the other end of the pipe.
   --- End of inner exception stack trace ---
   at Microsoft.PowerShell.ConsoleControl.GetConsoleScreenBufferInfo(SafeFileHandle consoleHandle)
   at Microsoft.PowerShell.ConsoleHostRawUserInterface.get_CursorPosition()
   at Microsoft.PowerShell.ConsoleHost.InputLoop.Run(Boolean inputLoopIsNested)
   at Microsoft.PowerShell.ConsoleHost.InputLoop.RunNewInputLoop(ConsoleHost parent, Boolean isNested)
   at Microsoft.PowerShell.ConsoleHost.EnterNestedPrompt()
   at Microsoft.PowerShell.ConsoleHost.DoRunspaceLoop(String initialCommand, Boolean skipProfiles, Collection`1 initialCommandArgs, Boolean staMode, String configurationName, String configurationFilePath)
   at Microsoft.PowerShell.ConsoleHost.Run(CommandLineParameterParser cpp, Boolean isPrestartWarned)
   at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText, Boolean issProvidedExternally)
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc)
Stack:
   at System.Environment.FailFast(System.String, System.Exception)
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32)
   at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])

Event ID: 1000

Faulting application name: OpenConsole.exe, version: 1.18.2310.9002, time stamp: 0x65248ade
Faulting module name: OpenConsole.exe, version: 1.18.2310.9002, time stamp: 0x65248ade
Exception code: 0xc0000094
Fault offset: 0x0000000000002be2
Faulting process id: 0x0x1238
Faulting application start time: 0x0x1DA051E9B66E886
Faulting application path: C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.18.2822.0_x64__8wekyb3d8bbwe\OpenConsole.exe
Faulting module path: C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.18.2822.0_x64__8wekyb3d8bbwe\OpenConsole.exe
Report Id: 84ce78c7-193c-4016-9a39-6bdb0231e18f
Faulting package full name: Microsoft.WindowsTerminal_1.18.2822.0_x64__8wekyb3d8bbwe
Faulting package-relative application ID: App
1
### Tasks
Originally created by @farag2 on GitHub (Oct 22, 2023). Originally assigned to: @lhecker on GitHub. ### Windows Terminal version 1.18.2822.0 ### Windows build number 10.0.22621.2428 ### Other Software ```powershell cls [Console]::CursorTop = 20 function Show-Menu { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [array] $Menu, [Parameter(Mandatory = $true)] [int] $Default ) # https://github.com/microsoft/terminal/issues/14992 [System.Console]::BufferHeight += $Menu.Count $minY = [Console]::CursorTop $y = [Math]::Max([Math]::Min($Default, $Menu.Count), 0) do { [Console]::CursorTop = $minY [Console]::CursorLeft = 0 $i = 0 foreach ($item in $Menu) { if ($i -ne $y) { Write-Information -MessageData (' {1} ' -f ($i+1), $item) -InformationAction Continue } else { Write-Information -MessageData ('[ {1} ]' -f ($i+1), $item) -InformationAction Continue } $i++ } $k = [Console]::ReadKey() switch ($k.Key) { "UpArrow" { if ($y -gt 0) { $y-- } } "DownArrow" { if ($y -lt ($Menu.Count - 1)) { $y++ } } "Enter" { return $Menu[$y] } } } while ($k.Key -notin ([ConsoleKey]::Escape, [ConsoleKey]::Enter)) } do { $Choice = Show-Menu -Menu @("Yes", "No", "Warning") -Default 2 switch ($Choice) { $Yes { continue } $No { "No" } $KeyboardArrows {} } } until ($Choice -ne "Warning") ``` ### Steps to reproduce Run script and choose "Warning" answer as much as you can. At the end Terminal will be crashed when interactive menu reaches the console window bottom. ### Expected Behavior It should continue waiting for a right answer without crashing ### Actual Behavior Terminal is crashed. Tested with all PowerShell versions. Pure PowerShell without Terminal has no crash. Also a Terminal Preview version has no crash too! Tested on `1.19.2682.0`. Event ID: 1025 ``` Application: pwsh.exe CoreCLR Version: 7.0.1123.42427 .NET Version: 7.0.11 Description: The application requested process termination through System.Environment.FailFast. Message: The Win32 internal error "No process is on the other end of the pipe." 0xE9 occurred while getting console output buffer information. Contact Microsoft Customer Support Services. Description: The process was terminated due to an unhandled exception.System.Management.Automation.Host.HostException: The Win32 internal error "No process is on the other end of the pipe." 0xE9 occurred while getting console output buffer information. Contact Microsoft Customer Support Services. ---> System.ComponentModel.Win32Exception (233): No process is on the other end of the pipe. --- End of inner exception stack trace --- at Microsoft.PowerShell.ConsoleControl.GetConsoleScreenBufferInfo(SafeFileHandle consoleHandle) at Microsoft.PowerShell.ConsoleHostRawUserInterface.get_CursorPosition() at Microsoft.PowerShell.ConsoleHost.InputLoop.Run(Boolean inputLoopIsNested) at Microsoft.PowerShell.ConsoleHost.InputLoop.RunNewInputLoop(ConsoleHost parent, Boolean isNested) at Microsoft.PowerShell.ConsoleHost.EnterNestedPrompt() at Microsoft.PowerShell.ConsoleHost.DoRunspaceLoop(String initialCommand, Boolean skipProfiles, Collection`1 initialCommandArgs, Boolean staMode, String configurationName, String configurationFilePath) at Microsoft.PowerShell.ConsoleHost.Run(CommandLineParameterParser cpp, Boolean isPrestartWarned) at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText, Boolean issProvidedExternally) at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc) Stack: at System.Environment.FailFast(System.String, System.Exception) at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32) at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[]) ``` Event ID: 1000 ``` Faulting application name: OpenConsole.exe, version: 1.18.2310.9002, time stamp: 0x65248ade Faulting module name: OpenConsole.exe, version: 1.18.2310.9002, time stamp: 0x65248ade Exception code: 0xc0000094 Fault offset: 0x0000000000002be2 Faulting process id: 0x0x1238 Faulting application start time: 0x0x1DA051E9B66E886 Faulting application path: C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.18.2822.0_x64__8wekyb3d8bbwe\OpenConsole.exe Faulting module path: C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.18.2822.0_x64__8wekyb3d8bbwe\OpenConsole.exe Report Id: 84ce78c7-193c-4016-9a39-6bdb0231e18f Faulting package full name: Microsoft.WindowsTerminal_1.18.2822.0_x64__8wekyb3d8bbwe Faulting package-relative application ID: App ``` <img width="201" alt="1" src="https://github.com/microsoft/terminal/assets/10544660/20423be7-0ade-4859-bcdb-792de860bf2f"> ```[tasklist] ### Tasks ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20713