Skip to content

System.ArgumentOutOfRangeException in PSReadLine when using HistoryRecall (Actual value was -1) #4195

@Drag0nSlay

Description

@Drag0nSlay

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

Oops, something went wrong.  Please report this bug with the details below.
Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new
-----------------------------------------------------------------------
Last 1 Keys:
 UpArrow

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: top
Actual value was -1.
   at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
   at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
   at Microsoft.PowerShell.PSConsoleReadLine.HistoryRecall(Int32 direction)
   at Microsoft.PowerShell.PSConsoleReadLine.PreviousHistory(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)

Screenshot

Bug

Environment data

PS Version: 
Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  4780

PS HostName: ConsoleHost
PSReadLine Version: 
Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      0      -1

PSReadLine EditMode: 
EditMode
--------
 Windows

OS: 
Platform ServicePack Version      VersionString
-------- ----------- -------      -------------
 Win32NT             10.0.19045.0 Microsoft Windows NT 10.0.19045.0

BufferWidth: 120
BufferHeight: 3000

Steps to reproduce

  1. Open PowerShell in VS Code or a standalone terminal.
  2. Press the UpArrow key to navigate through the command history.
  3. Observe that an ArgumentOutOfRangeException occurs, preventing access to the previous commands and displaying an error message related to the console buffer size.

Expected behavior

When pressing the UpArrow key, the previous command from the PowerShell history should be recalled and displayed in the command line for editing or execution. The history recall should work without throwing an exception, allowing smooth navigation through the history of commands without errors.

Actual behavior

When using the UpArrow key to recall previous commands from the PowerShell history, an ArgumentOutOfRangeException occurs. The exception message indicates that the "top" value is out of the valid range for the console buffer. Specifically, the "Actual value was -1," which causes the PSReadLine to fail when rendering the console history.

This issue prevents navigating through the command history and disrupts normal use of the console. The PowerShell session does not crash, but the exception interrupts the current input.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions