Skip to content
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

Helix crashed on "Undo change" (u) [undo] #5733

Closed
souserge opened this issue Jan 30, 2023 · 10 comments · Fixed by #5790
Closed

Helix crashed on "Undo change" (u) [undo] #5733

souserge opened this issue Jan 30, 2023 · 10 comments · Fixed by #5790
Assignees
Labels
C-bug Category: This is a bug

Comments

@souserge
Copy link

Summary

I had an opened JS file in helix. I accidentally pasted some text from the system clipboard several times by making a three-finger gesture swiping from right to left (the pasting action is probably due to me using tmux). I pressed 'u' to undo it and it said "Already at oldest change". After pressing Escape, I could undo the change but after pressing it a few times, Helix crashed with the error message presented in the Helix log. I may have tried writing the file with :w (don't remember exactly).

Additionally, I have the JavaScript language server running, and auto-format using prettier.

Reproduction Steps

I tried this:

  1. tmux
  2. hx file.js
  3. paste something form the system's clipboard.
  4. press u
  5. press <Esc>
  6. press u a few times
  7. press :w

I expected this to happen:

Changes are undone and the file is saved with formatting

Instead, this happened:

The editor has crashed.

Helix log

No related logs were recorded but the program crashed with the following error outputed to the terminal:

thread 'main' panicked at 'assertion failed: original_doc.len_chars() == self.len', helix-core/src/transaction.rs:265:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Platform

Linux (Fedora 37)

Terminal Emulator

alacritty 0.10.1

Helix Version

helix 22.12

@souserge souserge added the C-bug Category: This is a bug label Jan 30, 2023
@pascalkuthe
Copy link
Member

A bit of a longshot but the problem maybe fixed by #5711 if your file contains any non-ascii chars. Could you try again with that PR? Otherwise please post your file with which you experienced the crash so we can reproduce and test the problem ourselfs.

@gabydd
Copy link
Member

gabydd commented Jan 30, 2023

#1410 has the same panic, it seems to have to do with paste and then undo

@pascalkuthe
Copy link
Member

#1410 has the same panic, it seems to have to do with paste and then undo

Any kind of incorrect transaction applied to a document can cause crashes like these. A ton of different bugs can cause incorrect transactions to be produced so the panic message doesn't tell us much about the cause. Since #1410 was reported most of these issues have been fixed (many by @the-mikedavis). So this is likely a different bug. It sounds like it's LSP related hence I suggested #5711 since I had similar crashes while testing that (before I finally fixed them all)

@the-mikedavis
Copy link
Member

I can't reproduce this with just those steps: can you reliably reproduce this with some exact clipboard contents? If you can reproduce could you capture the full backtrace by setting RUST_BACKTRACE=1?

Also: do you have a language server installed for javascript and have you configured it to format on save?

@pascalkuthe
Copy link
Member

Also: do you have a language server installed for javascript and have you configured it to format on save?

I think he does, from the issue description:

Additionally, I have the JavaScript language server running, and auto-format using prettier.

Which reminded me of #4791 (hence my guess that #5711 may fix this)

@archseer
Copy link
Member

archseer commented Jan 31, 2023

I had a similar crash lately, it happened when I was pasting via middle click (and I might have been in insert mode?) then undo. It was a Go file in my case

@souserge
Copy link
Author

souserge commented Feb 2, 2023

@pascalkuthe @the-mikedavis I'm not sure if I reproduced the same bug I had last time, since now the panic output looks different. Nevertheless, the circumstances are very similar so it's probably caused by the same issue.

Some observations

  • The bug also appears with no user configuration file present (vanilla Helix settings).
  • I could not replicate it when having the mouse disabled via the config.toml --> [editor] --> mouse property.
  • It probably has to do with the LSP since I wasn't able to achieve the same error when the result of the pasting was valid JS code, or when I renamed the file to testHelixBug.txt. Since I was able to replicate it without saving, I think auto-format here is not involved.
  • It doesn't seem to depend on the shell (tried bash, zsh, and fish) or the terminal emulator (tried with alacritty, tilix, and the default GNOME terminal). Also tmux doesn't influence the result. I was able to replicate it in all cases (For the record, I haven't tried all possible combinations though).

Environment:

  • Fedora 37 running on Lenovo ThinkPad E590
  • Node v19.4.0 (installed via nvm v2.2.11)
  • Globally installed [email protected]
  • Helix editor version 22.12 (installed via the COPR dnf package varlad/helix)
  • JavaScript LSP set up (green tick box in hx --heath)
  • No user configuration. Specifically, [editor] --> mouse NOT set to false

Steps to replicate

(I also recorded it using asciinema).

  1. create a JS file (e.g. testHelixbug.js) with the following contents:
// Make sure the mouse isn't disabled (editor.mouse in config.toml)
// Steps to reproduce:
//   * Click on the last line (marked with tilde)
//   * Press: <middle-click> <middle-click> <middle-click> u <middle-click> u

function test() {
  return "Hello, world!";
}
  1. Copy the following text to your system clipboard: helix editor
  2. Open the file: $ RUST_BACKTRACE=full hx testHelixBug.js
  3. Click somewhere on the last line (should be marked with a tilda) with a mouse. You don't need to actually click it as long as you have the cursor there.
  4. Press: <middle-click> <middle-click> <middle-click> u <middle-click> u
  5. Observe the crash (Position and len might differ):
thread 'main' panicked at 'Position 307 is out of range for changeset len 302!', helix-core/src/transaction.rs:397:13
stack backtrace:
   0:     0x558872968465 - <unknown>
   1:     0x5588720489ae - <unknown>
   2:     0x558872962105 - <unknown>
   3:     0x558872969de3 - <unknown>
   4:     0x558872969aef - <unknown>
   5:     0x55887296a4af - <unknown>
   6:     0x55887296a314 - <unknown>
   7:     0x55887296896c - <unknown>
   8:     0x55887296a062 - <unknown>
   9:     0x558871fb5e43 - <unknown>
  10:     0x558872158572 - <unknown>
  11:     0x558872712a8f - <unknown>
  12:     0x558872714034 - <unknown>
  13:     0x558872608159 - <unknown>
  14:     0x55887248e646 - <unknown>
  15:     0x55887248e56e - <unknown>
  16:     0x558872490e5b - <unknown>
  17:     0x5588725c7845 - <unknown>
  18:     0x5588727afcc7 - <unknown>
  19:     0x5588727d058f - <unknown>
  20:     0x558872809a79 - <unknown>
  21:     0x55887282aa70 - <unknown>
  22:     0x5588727d1301 - <unknown>
  23:     0x5588728110f3 - <unknown>
  24:     0x5588728215f9 - <unknown>
  25:     0x55887295d6ba - <unknown>
  26:     0x5588727d1408 - <unknown>
  27:     0x7f5558d05510 - __libc_start_call_main
  28:     0x7f5558d055c9 - __libc_start_main@GLIBC_2.2.5
  29:     0x558871ff21d5 - <unknown>
  30:                0x0 - <unknown>

@pascalkuthe
Copy link
Member

pascalkuthe commented Feb 2, 2023

Thank you so much for following up on this! I can reproduce this easily on the latest master and am looking into a fix. Detail reproduction cases like this are greatly appreciated. Not LSP related tough as this also occurs with :language text

@pascalkuthe
Copy link
Member

pascalkuthe commented Feb 2, 2023

turns out all paste commands don't append to history when called as a typable commands (which is a well known cause of crashes in combination with undo). Middle mouse just call :clipboard-paste-before, the same crash can also be reproduced by just using the typable command directly. #5790 fixes the problem

@scimas
Copy link
Contributor

scimas commented Feb 12, 2024

I have managed to get a panic very similar to this issue.

thread 'main' panicked at D:\a\helix\helix\helix-core\src\transaction.rs:461:9:
Positions [(8682, After)] are out of range for changeset len 8674!
note: run with `RUST...

Happened on an undo after a clipboard-paste-replace. I didn't open a new issue because I don't have reproduction steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants