Skip to content

System.ArgumentOutOfRangeException PSReadLine: 2.1.0-beta1 PowerShell: 7.1.0-preview.2 #1495

Closed

Description

Environment

Name Value
PS version 7.1.0-preview.2
PSReadline version 2.1.0-beta1
os 10.0.19613.1000 (WinBuild.160101.0800)
PS file version 7.1.0.0
HostName ConsoleHost
BufferWidth 127
BufferHeight 1000

Last 200 Keys

 I n A r c h i v e F o r m a t ] : : X Z ) Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow LeftArrow LeftArrow Shift+Ctrl+LeftArrow $ r . C o n t e n t Ctrl+z Escape # Backspace $ s RightArrow Spacebar RightArrow LeftArrow RightArrow Shift+Ctrl+LeftArrow Shift+Ctrl+LeftArrow Ctrl+RightArrow Ctrl+RightArrow RightArrow Spacebar LeftArrow LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow LeftArrow Shift+LeftArrow Shift+LeftArrow Shift+LeftArrow Shift+LeftArrow Shift+LeftArrow Shift+LeftArrow Shift+LeftArrow Delete Delete Enter
 $ s e v Tab Enter
 UpArrow UpArrow Ctrl+a Ctrl+x N e w - O b j e c t Spacebar - T y p e N a m e Spacebar S e v e n Z i p E x t r a c t o r Spacebar - A r g u m e n t L i s t Spacebar @ ( $ s e v e n Z i p S t r e a m , [ S e v e n Z i p . I n A r c h i v e F o r m a t ] : : X Z ) Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+RightArrow LeftArrow LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+RightArrow [ ] Backspace Backspace Escape

Exception

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'length')
   at System.Text.StringBuilder.Remove(Int32 startIndex, Int32 length)
   at Microsoft.PowerShell.PSConsoleReadLine.EditItemInsertChar.Undo()
   at Microsoft.PowerShell.PSConsoleReadLine.RevertLine(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

Investigating...

Expected behavior

Actual behavior

Activity

  1. ghost added
    Needs-Triage 🔍It's a new issue that core contributor team needs to triage.
    on Apr 30, 2020
  2. iSazonov commented on Apr 30, 2020

    @iSazonov

    Investigating...

    Yes, please.

    See also #1469

  3. lzybkr commented on Apr 30, 2020

    @lzybkr
    Contributor

    I'm guessing this will be hard to reproduce.

    Here are some useful details that may help:

    • After you type Enter, the command you entered and the undo stack is saved in memory - just the command line is saved in your history file.
    • When you recall a previous command with editing history (UpArrow), you can undo (e.g. Ctrl+z) immediately.
    • Esc actually uses the undo stack.
  4. daxian-dbw commented on May 1, 2020

    @daxian-dbw
    Member

    I found the issue and also the consistent repro:

    1. in Windows edit mode, run Set-PSReadLineKeyHandler -Chord "Ctrl+f" -Function ForwardWord
    2. Type git checkout -b blah origin/nonexist and press Enter
    3. Type git ch, and press Ctrl+f, then press Enter
    4. Press UpArrow, then press Escape

    The issue will be fixed in #1496 (the 2nd commit).

  5. daxian-dbw commented on May 1, 2020

    @daxian-dbw
    Member

    From Daniel Ferreira (@daniel0x00)

    I see the same on PSReadLine 2.1.0-beta1:

    Environment

    PSReadLine: 2.1.0-beta1
    PowerShell: 7.0.0
    OS: Microsoft Windows 10.0.17763
    Last 200 Keys

    Ctrl+Backspace Backspace Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow >Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow Ctrl+LeftArrow $ redactedobject Spacebar = Spacebar Enter
    $ redactedobject Spacebar = Spacebar $ redactedobject . a r g s Enter
    $ redactedobject  Spacebar = Spacebar $ redactedobject  Spacebar | Spacebar s e l e c t Spacebar * , Spacebar @ { n = ' c o m m a n d ' ; e = { $ redactedobject  } } , Spacebar @ { n = ' >REDACTED ' ; e = { $ e n v : C O M P U T E R N A M E } } Enter
    Enter
    $ redactedobject Enter
    Enter
    UpArrow UpArrow UpArrow DownArrow DownArrow UpArrow UpArrow UpArrow Escape
    

    Exception

    System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
      at System.Text.StringBuilder.Insert(Int32 index, String value)
      at Microsoft.PowerShell.PSConsoleReadLine.EditItemDelete.Undo()
      at Microsoft.PowerShell.PSConsoleReadLine.RevertLine(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)
    
  6. daxian-dbw commented on May 1, 2020

    @daxian-dbw
    Member

    From James O'Neill (@jhoneill)

    Another one here. Identical stack trace displayed to Daniel Ferreira (@daniel0x00) above.
    It seems to be be fairly common and easy to repro in VS Code integrated shell

    Put in a long line at the last line in the window, press [ESC] and POW! Something seems to do its sums wrongly and think it should be removing stuff from a line after the end of the window.
    If I move the cursor to left of about 176 (even if the line is very long) all is OK. If I'm not on the last line, all is OK. but cursor to near the bottom right is what triggers it . Whilst very ugly it doesn't do any real harm apart from displaying the error the session seems unaffected

    PS version: 7.0.0
    PSReadline version: 2.1.0-beta1'; ProjectUri = 'https://github.com/PowerShell/PSReadLine
    os: 10.0.18362.1 (WinBuild.160101.0800)
    PS file version: 7.0.0.0
    HostName: Visual Studio Code Host
    BufferWidth: 220
    BufferHeight: 32
    
  7. added
    Issue-BugIt 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.
    on May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIt either shouldn't be doing this or needs an investigation.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions