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

24.03: byte_slice(): Byte range out of bounds #10497

Open
krukas opened this issue Apr 17, 2024 · 20 comments
Open

24.03: byte_slice(): Byte range out of bounds #10497

krukas opened this issue Apr 17, 2024 · 20 comments
Labels
C-bug Category: This is a bug

Comments

@krukas
Copy link

krukas commented Apr 17, 2024

Summary

Just starting to use Helix and love it 👏

Today i had two crashes, hard to pinpoint what was happening or reproduce. both time did an undo and then go into insert mode.

thread 'main' panicked at /home/abuild/rpmbuild/BUILD/helix-24.03/vendor/ropey/src/slice.rs:703:23:
byte_slice(): Byte range out of bounds: byte range 0..34, Rope/RopeSlice byte length 12
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: ropey::slice::RopeSlice::byte_slice
   3: helix_core::indent::treesitter_indent_for_pos
   4: helix_core::indent::indent_for_newline
   5: helix_term::commands::insert::insert_newline
   6: helix_term::ui::editor::EditorView::handle_keymap_event::{{closure}}
   7: helix_term::ui::editor::EditorView::handle_keymap_event
   8: helix_term::ui::editor::EditorView::insert_mode
   9: <helix_term::ui::editor::EditorView as helix_term::compositor::Component>::handle_event
  10: helix_term::compositor::Compositor::handle_event
  11: hx::main_impl::{{closure}}
  12: tokio::runtime::park::CachedParkThread::block_on
  13: tokio::runtime::context::runtime::enter_runtime
  14: tokio::runtime::runtime::Runtime::block_on
  15: hx::main

Reproduction Steps

No response

Helix log

~/.cache/helix/helix.log
2024-04-17T09:30:24.669 helix_lsp::transport [ERROR] bash-language-server err <- "(node:13578) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.\n"
2024-04-17T09:30:24.670 helix_lsp::transport [ERROR] bash-language-server err <- "(Use `node21 --trace-deprecation ...` to show where the warning was created)\n"
2024-04-17T09:33:04.152 helix_term::application [WARN] Ignoring a client/registerCapability request because dynamic capability registration is not enabled. Please report this upstream to the language server
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"initialize\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/foldingRange\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/documentSymbol\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/formatting\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/completion\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/hover\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/documentLink\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/semanticTokens/full\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/prepareRename\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/rename\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"initialized\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"textDocument/didOpen\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"textDocument/didSave\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"textDocument/didChange\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"workspace/didChangeConfiguration\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"textDocument/didClose\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"taplo/convertToJson\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"taplo/convertToToml\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"workspace/didChangeWorkspaceFolders\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"taplo/associatedSchema\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"taplo/listSchemas\"\n"
2024-04-17T09:38:30.335 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"taplo/associateSchema\"\n"
2024-04-17T09:38:30.343 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: LSP server listening transport=\"stdio\"\n"
2024-04-17T09:38:45.603 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: received shutdown request id=Number(1) method=shutdown\n"
2024-04-17T09:47:06.591 helix_lsp::transport [ERROR] bash-language-server err: <- StreamClosed
2024-04-17T09:47:06.591 helix_lsp::transport [ERROR] err: <- Other(failed to send a message to server

Caused by:
    channel closed)
2024-04-17T09:48:20.600 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"initialize\"\n"
2024-04-17T09:48:20.600 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/foldingRange\"\n"
2024-04-17T09:48:20.600 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/documentSymbol\"\n"
2024-04-17T09:48:20.600 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/formatting\"\n"
2024-04-17T09:48:20.600 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/completion\"\n"
2024-04-17T09:48:20.600 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/hover\"\n"
2024-04-17T09:48:20.600 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/semanticTokens/full\"\n"
2024-04-17T09:48:20.600 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/documentLink\"\n"
2024-04-17T09:48:20.600 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/prepareRename\"\n"
2024-04-17T09:48:20.600 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"textDocument/rename\"\n"
2024-04-17T09:48:20.600 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"initialized\"\n"
2024-04-17T09:48:20.601 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"textDocument/didOpen\"\n"
2024-04-17T09:48:20.601 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"textDocument/didChange\"\n"
2024-04-17T09:48:20.601 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"textDocument/didSave\"\n"
2024-04-17T09:48:20.601 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"textDocument/didClose\"\n"
2024-04-17T09:48:20.601 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"workspace/didChangeConfiguration\"\n"
2024-04-17T09:48:20.601 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"workspace/didChangeWorkspaceFolders\"\n"
2024-04-17T09:48:20.601 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"taplo/convertToJson\"\n"
2024-04-17T09:48:20.601 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"taplo/convertToToml\"\n"
2024-04-17T09:48:20.601 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"taplo/listSchemas\"\n"
2024-04-17T09:48:20.601 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered request handler method=\"taplo/associatedSchema\"\n"
2024-04-17T09:48:20.601 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: registered notification handler method=\"taplo/associateSchema\"\n"
2024-04-17T09:48:20.610 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: LSP server listening transport=\"stdio\"\n"
2024-04-17T09:48:28.530 helix_lsp::transport [ERROR] taplo err <- " INFO taplo: received shutdown request id=Number(3) method=shutdown\n"
2024-04-17T10:46:08.081 helix_lsp::transport [ERROR] bash-language-server err <- "(node:26769) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.\n"
2024-04-17T10:46:08.081 helix_lsp::transport [ERROR] bash-language-server err <- "(Use `node21 --trace-deprecation ...` to show where the warning was created)\n"
2024-04-17T10:48:50.684 helix_term::application [WARN] Ignoring a client/registerCapability request because dynamic capability registration is not enabled. Please report this upstream to the language server
2024-04-17T11:16:04.548 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(17)), original request likely timed out
2024-04-17T11:20:30.392 helix_term::application [WARN] Ignoring a client/registerCapability request because dynamic capability registration is not enabled. Please report this upstream to the language server
2024-04-17T11:33:17.557 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(45)), original request likely timed out
2024-04-17T11:38:01.806 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(67)), original request likely timed out
2024-04-17T11:38:01.969 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(68)), original request likely timed out
2024-04-17T11:38:02.130 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(69)), original request likely timed out
2024-04-17T11:38:02.292 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(70)), original request likely timed out
2024-04-17T11:38:02.454 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(71)), original request likely timed out
2024-04-17T11:56:28.920 helix_term::application [WARN] Ignoring a client/registerCapability request because dynamic capability registration is not enabled. Please report this upstream to the language server
2024-04-17T12:42:34.749 helix_lsp::transport [ERROR] err: <- Other(failed to send a message to server

Caused by:
    channel closed)
2024-04-17T12:42:34.749 helix_lsp::transport [ERROR] typescript-language-server err: <- StreamClosed
2024-04-17T12:42:34.751 helix_lsp::transport [ERROR] err: <- Other(failed to send a message to server

Caused by:
    channel closed)
2024-04-17T12:42:34.751 helix_lsp::transport [ERROR] yaml-language-server err: <- StreamClosed
2024-04-17T12:42:34.752 helix_lsp::transport [ERROR] err: <- Other(failed to send a message to server

Caused by:
    channel closed)
2024-04-17T12:42:34.752 helix_lsp::transport [ERROR] docker-langserver err: <- StreamClosed
2024-04-17T12:45:10.872 helix_term::application [WARN] Ignoring a client/registerCapability request because dynamic capability registration is not enabled. Please report this upstream to the language server
2024-04-17T12:47:29.729 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(3)), original request likely timed out
2024-04-17T13:38:13.436 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(16)), original request likely timed out
2024-04-17T14:43:08.046 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(33)), original request likely timed out
2024-04-17T15:00:42.182 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(38)), original request likely timed out
2024-04-17T15:16:29.924 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(79)), original request likely timed out
2024-04-17T15:16:34.736 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(81)), original request likely timed out
2024-04-17T15:16:42.876 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(86)), original request likely timed out
2024-04-17T15:16:43.030 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(87)), original request likely timed out
2024-04-17T15:16:51.447 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(90)), original request likely timed out
2024-04-17T15:18:13.674 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(94)), original request likely timed out
2024-04-17T15:18:47.266 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(100)), original request likely timed out
2024-04-17T15:19:11.607 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(107)), original request likely timed out
2024-04-17T15:48:48.663 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(130)), original request likely timed out
2024-04-17T15:48:48.698 helix_lsp::transport [ERROR] pylsp err <- "2024-04-17 15:48:48,654 CEST - WARNING - pylsp.workspace - There was an error while trying to initialize progress reporting.Likely progress reporting was used in a synchronous LSP handler, which is not supported by progress reporting yet. To prevent waiting for the timeout you can set `skip_token_initialization=True`. Not every editor will show progress then, but many will.\n"
2024-04-17T15:48:48.698 helix_lsp::transport [ERROR] pylsp err <- "Traceback (most recent call last):\n"
2024-04-17T15:48:48.698 helix_lsp::transport [ERROR] pylsp err <- "  File \"/home/maikel/.local/share/pipx/venvs/python-lsp-server/lib64/python3.11/site-packages/pylsp/workspace.py\", line 252, in _progress_begin\n"
2024-04-17T15:48:48.698 helix_lsp::transport [ERROR] pylsp err <- "    ).result(timeout=1.0)\n"
2024-04-17T15:48:48.698 helix_lsp::transport [ERROR] pylsp err <- "      ^^^^^^^^^^^^^^^^^^^\n"
2024-04-17T15:48:48.698 helix_lsp::transport [ERROR] pylsp err <- "  File \"/usr/lib64/python3.11/concurrent/futures/_base.py\", line 458, in result\n"
2024-04-17T15:48:48.698 helix_lsp::transport [ERROR] pylsp err <- "    raise TimeoutError()\n"
2024-04-17T15:48:48.698 helix_lsp::transport [ERROR] pylsp err <- "TimeoutError\n"
2024-04-17T15:48:49.066 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(131)), original request likely timed out
2024-04-17T15:48:49.151 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(132)), original request likely timed out
2024-04-17T15:48:49.219 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(133)), original request likely timed out
2024-04-17T15:48:49.283 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(134)), original request likely timed out
2024-04-17T16:29:22.555 helix_lsp::util [WARN] LSP position Position { line: 2381, character: 0 } out of range assuming EOF
2024-04-17T16:29:22.555 helix_lsp::util [WARN] LSP position Position { line: 2381, character: 100 } out of range assuming EOF
2024-04-17T16:29:25.969 helix_lsp::util [WARN] LSP position Position { line: 2381, character: 0 } out of range assuming EOF
2024-04-17T16:29:25.969 helix_lsp::util [WARN] LSP position Position { line: 2381, character: 100 } out of range assuming EOF
2024-04-17T16:29:27.206 helix_lsp::util [WARN] LSP position Position { line: 2381, character: 0 } out of range assuming EOF
2024-04-17T16:29:27.206 helix_lsp::util [WARN] LSP position Position { line: 2381, character: 100 } out of range assuming EOF
2024-04-17T16:29:27.774 helix_lsp::util [WARN] LSP position Position { line: 2381, character: 0 } out of range assuming EOF
2024-04-17T16:29:27.774 helix_lsp::util [WARN] LSP position Position { line: 2381, character: 100 } out of range assuming EOF
2024-04-17T16:31:15.256 helix_lsp::transport [ERROR] Tried sending response into a closed channel (id=Num(182)), original request likely timed out
2024-04-17T16:32:26.473 helix_lsp::transport [ERROR] yaml-language-server err: <- StreamClosed
2024-04-17T16:32:26.474 helix_lsp::transport [ERROR] err: <- Other(failed to send a message to server

Caused by:
    channel closed

Stack backtrace:
   0: helix_lsp::transport::Transport::process_server_message::{{closure}}
   1: helix_lsp::transport::Transport::recv::{{closure}}
   2: tokio::runtime::task::core::Core<T,S>::poll
   3: tokio::runtime::task::harness::Harness<T,S>::poll
   4: tokio::runtime::scheduler::multi_thread::worker::Context::run_task
   5: tokio::runtime::scheduler::multi_thread::worker::Context::run
   6: tokio::runtime::context::runtime::enter_runtime
   7: tokio::runtime::scheduler::multi_thread::worker::run
   8: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll
   9: tokio::runtime::task::core::Core<T,S>::poll
  10: tokio::runtime::task::harness::Harness<T,S>::poll
  11: tokio::runtime::blocking::pool::Inner::run
  12: std::sys_common::backtrace::__rust_begin_short_backtrace
  13: core::ops::function::FnOnce::call_once{{vtable.shim}}
  14: std::sys::pal::unix::thread::Thread::new::thread_start
  15: start_thread
  16: clone3)

Platform

Linux

Terminal Emulator

Alacritty with zellij

Installation Method

zypper (OpenSuse tumbleweed)

Helix Version

helix 24.3 (2cadec0)

@krukas krukas added the C-bug Category: This is a bug label Apr 17, 2024
@pascalkuthe
Copy link
Member

I know where in the code the crash occurs but I can't find anything wrong with it so we need more Information:

  • what language are you using
  • cab you share a file where this crash happened?

@krukas
Copy link
Author

krukas commented Apr 17, 2024

I know where in the code the crash occurs but I can't find anything wrong with it so we need more Information:

* what language are you using

* cab you share a file where this crash happened?
  • was in a large python file, around 3500 lines.
  • no, code is from work.

@pascalkuthe
Copy link
Member

Does your document contain carrige return (CR) linenedings (just \r instead of \r\n or \n)?

I think that's the most likely explanation for this and in that case I know how to fix this.

@pascalkuthe
Copy link
Member

Hmm nevemind I guess I don't see crashes with CR in testing. I thought tree sitter counted those as newlines but we didn't. Not sure what exactly this is causing that it's pretty weird and I can't reproduce.

@krukas
Copy link
Author

krukas commented Apr 17, 2024

I checked file and are all \n. I think i also did a selection with mouse and yank (just find out it does an auto yank with mouse). Tried multiple combination of those actions and could not reproduce.

I have set the env RUST_BACKTRACE=full, don't know if that gives more details. Next time I will try to write down exact steps.

Can you increase the log verbosity? Maybe to see all commands/keybinds?

@shaleh
Copy link
Contributor

shaleh commented Apr 18, 2024

hx -vvv gets you max verbosity.

@omentic
Copy link
Contributor

omentic commented Apr 22, 2024

@krukas are you running any patches? I get this issue all the time because of some underlying bug that's exposed undo/redo and a patch I have that keeps the editor in insert mode always, but I've not bothered to rebase my fork & debug.

Also note that a fix for similar issue (#6645) was merged just after the 24.3 release. Maybe try that out?

@pascalkuthe
Copy link
Member

@krukas are you running any patches? I get this issue all the time because of some underlying bug that's exposed undo/redo and a patch I have that keeps the editor in insert mode always, but I've not bothered to rebase my fork & debug.

Also note that a fix for similar issue (#6645) was merged just after the 24.3 release. Maybe try that out?

The panic message will not tell you anyrhing. If anyrhing goes wrong in the editor it usually ends up in a panic like that.

I know what code is causing it and there is very little that can go wrong there (nothing related to undo or the rendering system). Tree sitter ir producing an invalid point offset/we are reading it.

I will probably just fix this by removing the use of tree sitter points entirely and just always use byte positions instead

@krukas
Copy link
Author

krukas commented Apr 23, 2024

@krukas are you running any patches? I get this issue all the time because of some underlying bug that's exposed undo/redo and a patch I have that keeps the editor in insert mode always, but I've not bothered to rebase my fork & debug.

Also note that a fix for similar issue (#6645) was merged just after the 24.3 release. Maybe try that out?

I'm running 24.03 from Opensuse tumbleweed repo, don't know if some patches are applied to that.

@omentic
Copy link
Contributor

omentic commented Apr 23, 2024

The panic message will not tell you anything. If anything goes wrong in the editor it usually ends up in a panic like that.

Oops, I misread the panic message... 🤦 that other issue is not similar, never mind.

@krukas
Copy link
Author

krukas commented Apr 30, 2024

had another crash after I selected text with mouse and used space+y, could not reproduce and this time it was a small .gitignore.rej file.

The file in question:
.gitignore.rej.txt

thread 'main' panicked at /home/abuild/rpmbuild/BUILD/helix-24.03/vendor/ropey/src/slice.rs:360:41:
called `Result::unwrap()` on an `Err` value: Char index out of bounds: char index 396, Rope/RopeSlice char length 243
stack backtrace:
   0:     0x55c5cb62aaed - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3a3e14066d08445b
   1:     0x55c5ca9d4350 - core::fmt::write::h635b969b0c73ca1c
   2:     0x55c5cb635e53 - std::io::Write::write_fmt::h32a392dc332161f1
   3:     0x55c5cb62a874 - std::sys_common::backtrace::print::haebafeedddb3c231
   4:     0x55c5cb62ba90 - std::panicking::default_hook::{{closure}}::hbe6b35352e97edda
   5:     0x55c5cb62b767 - std::panicking::default_hook::ha3d28f6760dc7873
   6:     0x55c5cb62c0af - std::panicking::rust_panic_with_hook::hbe5a76d502748239
   7:     0x55c5cb62bdfa - std::panicking::begin_panic_handler::{{closure}}::h4d6ed894446a10f5
   8:     0x55c5cb62ad26 - std::sys_common::backtrace::__rust_end_short_backtrace::h5a53e39732234b5b
   9:     0x55c5cb62bb54 - rust_begin_unwind
  10:     0x55c5ca8e3105 - core::panicking::panic_fmt::h09f37a9c2cf6ceee
  11:     0x55c5ca8e3043 - core::result::unwrap_failed::heb7cf98b365f9694
  12:     0x55c5cac29828 - helix_core::graphemes::nth_prev_grapheme_boundary::he6fc00b2016c791d
  13:     0x55c5caba631e - helix_core::selection::Range::grapheme_aligned::habc27d12e024d577
  14:     0x55c5caba7fed - helix_core::selection::Selection::ensure_invariants::h7e5258b362caa693
  15:     0x55c5cb3233a0 - helix_view::document::Document::set_selection::h634a854285e4fa64
  16:     0x55c5cb1564dc - helix_term::ui::raw_regex_prompt::{{closure}}::h6857520fb59765f8
  17:     0x55c5cb153e8d - <helix_term::ui::prompt::Prompt as helix_term::compositor::Component>::handle_event::h1e171bbd2cd0919e
  18:     0x55c5cae2d565 - helix_term::compositor::Compositor::handle_event::ha996701f147846b1
  19:     0x55c5cb3c8e3b - hx::main_impl::{{closure}}::hbd7a2969b05d8b56
  20:     0x55c5cb3c641c - tokio::runtime::park::CachedParkThread::block_on::h2cd3f55f5a82dc98
  21:     0x55c5cb44c386 - tokio::runtime::context::runtime::enter_runtime::ha97b7f446efa872c
  22:     0x55c5cb41cd0c - tokio::runtime::runtime::Runtime::block_on::h3c252f1686fdf08e
  23:     0x55c5cb44e893 - hx::main::hfa3be32ee38b15b1
  24:     0x55c5cb43a243 - std::sys_common::backtrace::__rust_begin_short_backtrace::h38bba8e9a1cab6d1
  25:     0x55c5cb4166dd - std::rt::lang_start::{{closure}}::hdc5b84c44b99049d
  26:     0x55c5cb64df55 - std::rt::lang_start_internal::h84480a904ea3543b
  27:     0x55c5cb44e985 - main
  28:     0x7f6d5fe2a1f0 - __libc_start_call_main
  29:     0x7f6d5fe2a2b9 - __libc_start_main@GLIBC_2.2.5
  30:     0x55c5ca958ee5 - _start
  31:                0x0 - <unknown>

@kivikakk
Copy link

I had the same on a larger file just now (from work, so unfortunately can't share); don't have a full backtrace at hand but will run with RUST_BACKTRACE=1 in future to catch it if it happens!

thread 'main' panicked at /private/tmp/nix-build-helix-24.03.drv-0/helix-24.03-vendor.tar.gz/ropey/src/slice.rs:360:41:
called `Result::unwrap()` on an `Err` value: Char index out of bounds: char index 19926, Rope/RopeSlice char length 9763
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

It's notable to me that the file is indeed 9763 characters long at time of crash, and that the OOB index is slightly (400 chars) more than 2x that.

File was TypeScript, with LSP on, and Helix is 24.03 from NixOS unstable (uses source directly from GitHub release with no patches applied).

@carsoncall
Copy link

carsoncall commented Oct 14, 2024

I've noticed a similar issue on my machine. I didn't capture the RUST_BACKTRACE, but I know that, when I accept suggestions in Python (with pylsp) it deletes a character immediately after the insertion. If there isn't a character to delete, then it crashes. This is reproducible using the following steps:

  1. hx example.py
  2. In the resulting editor that opens, simply type imp, and the editor suggests import as a keyword. Select the suggestion and observe as the last endline char is deleted.
  3. Backspace the import, and repeat step 2.
  4. Helix crashes with the following error:
    """
    thread 'main' panicked at /usr/share/cargo/registry/ropey-1.6.1/src/slice.rs:656:9:
    Attempt to slice past end of RopeSlice: slice end 2, RopeSlice length 1
    note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
    """
    Some version info:
    hx --version: helix 24.7 (079f5442)
    pylsp --version: pylsp v1.11.0
    On Fedora 40 (Sway) with Wezterm.
    Also included is a .gif of the terminal, to demo the bug:
    helix-bug

@the-mikedavis
Copy link
Member

That is almost certainly #10689 instead

@Zapeth
Copy link

Zapeth commented Oct 29, 2024

Had the same error as @kivikakk happen just now, after switching from fullscreen view to window view (swaywm), in normal mode with a vertical split buffer of the same file:

thread 'main' panicked at /host/cargo/registry/src/index.crates.io-6f17d22bba15001f/ropey-1.6.1/src/slice.rs:360:41:
called `Result::unwrap()` on an `Err` value: Char index out of bounds: char index 25438, Rope/RopeSlice char length 25431

The actual file size of the saved file is 25398 bytes (might have been 25431 when crashing due to some small unsaved changes) and contains cpp language (no lsp active) with \n line endings.

Luckily I was only doing small edits with saving in between, so nothing was lost. I remember two other sessions where I think the same thing happened (weeks apart), but I didn't save the output so I don't know if it really was the same issue.

@ixxie
Copy link

ixxie commented Nov 1, 2024

I'm experiencing the same issue while editing a JS/Python repository in 24.07:

thread 'main' panicked at /build/helix-24.07-vendor.tar.gz/ropey/src/slice.rs:360:41:
called `Result::unwrap()` on an `Err` value: Char index out of bounds: char index 5897, Rope/RopeSlice char length 1957
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: helix_core::graphemes::nth_prev_grapheme_boundary
   4: helix_core::selection::Range::grapheme_aligned
   5: helix_core::selection::Selection::ensure_invariants
   6: helix_view::document::Document::set_selection
   7: helix_term::ui::raw_regex_prompt::{{closure}}
   8: helix_term::ui::prompt::Prompt::change_history
   9: <helix_term::ui::prompt::Prompt as helix_term::compositor::Component>::handle_event
  10: helix_term::compositor::Compositor::handle_event
  11: hx::main_impl::{{closure}}
  12: tokio::runtime::park::CachedParkThread::block_on
  13: tokio::runtime::context::runtime::enter_runtime
  14: tokio::runtime::runtime::Runtime::block_on
  15: hx::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I'm not 100% sure but it seems that this is happening when I switch to normal more. In my case its happening every 5-10m so if you need help reproducing/debugging it I'm available 😅

With RUST_BACKTRACE=full:
❯ hx -vvv .
thread 'main' panicked at /build/helix-24.07-vendor.tar.gz/ropey/src/slice.rs:360:41:
called `Result::unwrap()` on an `Err` value: Char index out of bounds: char index 7919, Rope/RopeSlice char length 1471
stack backtrace:
   0:     0x55b95bce6b57 - ::fmt::h8ebe18394a4d38c1
   1:     0x55b95af4af8b - core::fmt::write::ha0a58e1b31f3c795
   2:     0x55b95bcaf12f - std::io::Write::write_fmt::hf44822512e2ddbe5
   3:     0x55b95bcdef3a - std::panicking::default_hook::{{closure}}::h7bf7918f31cb7957
   4:     0x55b95bcdeb17 - std::panicking::default_hook::hcdb680cb5ef9d549
   5:     0x55b95bcdf6c8 - std::panicking::rust_panic_with_hook::h3972652105d7c699
   6:     0x55b95bce7147 - std::panicking::begin_panic_handler::{{closure}}::h325629d01629f674
   7:     0x55b95bce6d69 - std::sys::backtrace::__rust_end_short_backtrace::h533a501939048fce
   8:     0x55b95bcdf134 - rust_begin_unwind
   9:     0x55b95ae5e7c3 - core::panicking::panic_fmt::h54e352f1595c6bc3
  10:     0x55b95ae5e6f6 - core::result::unwrap_failed::h8ff0a47212477996
  11:     0x55b95b1b0074 - helix_core::graphemes::nth_prev_grapheme_boundary::h9080f6d06e938de2
  12:     0x55b95b1c1069 - helix_core::selection::Range::grapheme_aligned::h12d9eb197b95b8b6
  13:     0x55b95b1c2d7d - helix_core::selection::Selection::ensure_invariants::h3e0fd77b0be54185
  14:     0x55b95ba1b2d0 - helix_view::document::Document::set_selection::hcb5108d1a9e64d05
  15:     0x55b95b70aaf5 - helix_term::ui::raw_regex_prompt::{{closure}}::ha2bfdbd649ced1d3
  16:     0x55b95b6fc158 - ::handle_event::h661e55f9c8857101
  17:     0x55b95b76288d - helix_term::compositor::Compositor::handle_event::hdf41dd21ca7eee07
  18:     0x55b95ba5925a - hx::main_impl::{{closure}}::h08d78862bcf02420
  19:     0x55b95ba563df - tokio::runtime::park::CachedParkThread::block_on::hb5cf133f303c94f1
  20:     0x55b95baf5762 - tokio::runtime::context::runtime::enter_runtime::h856f177c1464180d
  21:     0x55b95bac1d5d - tokio::runtime::runtime::Runtime::block_on::hdc5ebd78ccdb2496
  22:     0x55b95baebd63 - hx::main::h3a62dbaa94294599
  23:     0x55b95bad99d3 - std::sys::backtrace::__rust_begin_short_backtrace::h409b9217f887534b
  24:     0x55b95bad2a9d - std::rt::lang_start::{{closure}}::h179fdaae2f2d47ac
  25:     0x55b95bcdbdc5 - std::rt::lang_start_internal::h5e80b9c2d90540eb
  26:     0x55b95baebe55 - main
  27:     0x7fa7d225027e - __libc_start_call_main
  28:     0x7fa7d2250339 - __libc_start_main_alias_2
  29:     0x55b95aec6ec5 - _start
  30:                0x0 - 
  

Edit: also happens in master

I now tested this with master (built with the flake.nix in the repository) and I still get the issue:

thread 'main' panicked at /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-vendor-cargo-deps/c19b7c6f923b580ac259164a89f2577984ad5ab09ee9d583b888f934adbbe8d0/ropey-1.6.1/src/slice.rs:360:41:
called `Result::unwrap()` on an `Err` value: Char index out of bounds: char index 14585, Rope/RopeSlice char length 1668
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@TornaxO7
Copy link
Contributor

TornaxO7 commented Dec 9, 2024

@ixxie may I as if you are able to provide the reproduction file (+ steps) or isn't it also possible to share the code?

@ixxie
Copy link

ixxie commented Dec 9, 2024

@ixxie may I as if you are able to provide the reproduction file (+ steps) or isn't it also possible to share the code?

Unfortunately the issue has been unpredictable and I have no systematic way of reproducing it. And actually, in recent weeks I have not experienced the issue at all.

@TornaxO7
Copy link
Contributor

@ixxie have you updated helix since the last crash?

@ixxie
Copy link

ixxie commented Dec 10, 2024

@ixxie have you updated helix since the last crash?

I'm on NixOS so I have a flake following nixpkgs unstable. I think I've rebuilt Helix at least a couple of times since the crashing occurred, and there is a good chance the issue was resolved to some upstream package update as well.

Sorry I can't help you narrow it down!

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

No branches or pull requests

10 participants