helix icon indicating copy to clipboard operation
helix copied to clipboard

panic: Char index out of bounds

Open alistaircarscadden opened this issue 8 months ago • 16 comments

Summary

thread 'main' panicked at C:\Users\runneradmin/.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 88087, Rope/RopeSlice char length 10230

Reproduction Steps

I tried this:

Panic occurred during selection over many lines. I clicked and dragged with mouse across about 20 lines and was intending to press "s" to select a specific word. I do not know if I had already clicked s or not when the panic happened.

I expected this to happen:

No panic

Instead, this happened:

Panic

Helix log

Dunno where this file is on Windows, no such ~/.cache dir

Platform

Windows

Terminal Emulator

alacritty 0.15.1 (0c405d5)

Installation Method

scoop

Helix Version

helix 25.01.1 (e7ac2fcd)

alistaircarscadden avatar Apr 10 '25 22:04 alistaircarscadden

I observed the same issue on osx, the logs contain nothing. I will try to run it with RUST_BACKTRACE=full and add more detail if I manage to reproduce it.

lupuszr avatar Apr 11 '25 08:04 lupuszr

I tried to replicate this but couldn't seem to trigger it myself. I am based on the latest master commit. If you can reliably reproduce, if possible, try out the latest master to see if it still happens.

RoloEdits avatar Apr 11 '25 08:04 RoloEdits

Its not reliable, what I observed it was failing when editing large files with 3-4k lines. I will try with master

lupuszr avatar Apr 11 '25 10:04 lupuszr

I just had it again on a 1-2KB file. Sorry but I don't know how to be more useful with reproducing it.

thread 'main' panicked at C:\Users\runneradmin/.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 5473, Rope/RopeSlice char length 389
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

alistaircarscadden avatar Apr 11 '25 21:04 alistaircarscadden

I think that might be #12626 which looks like it was fixed in 25.01.1 4bd17e542ef4b6103b7b5821418c02fe3ab2ad62. What version are you running @alistaircarscadden ?

RoloEdits avatar Apr 11 '25 21:04 RoloEdits

@RoloEdits helix 25.01.1 (e7ac2fcd)

alistaircarscadden avatar Apr 14 '25 02:04 alistaircarscadden

Also got this on NixOS, helix 25.01.1 (e7ac2fcd):

thread 'main' panicked at /build/helix-25.01.1-vendor/ropey-1.6.1/src/slice.rs:360:41:
called `Result::unwrap()` on an `Err` value: Char index out of bounds: char index 8290, Rope/RopeSlice char length 8289
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

nim65s avatar Apr 14 '25 20:04 nim65s

If you are able to build from source, from at least 4bd17e542ef4b6103b7b5821418c02fe3ab2ad62, hopefully that has fixed the issue.

RoloEdits avatar Apr 14 '25 23:04 RoloEdits

I am able to replicate this error on v25.01.1 by doing the following:

  1. Open helix and add three lines to the scratch file
  2. Open a new scratch file
  3. Split the window (horizontally or vertically)
  4. Go back to the original window and switch to the original scratch file
  5. Go to line 3 and press s
  6. Click in the other window with the single line scratch file and press escape

I'm guessing this isn't the only way to replicate the issue though

georgesmith46 avatar Apr 15 '25 13:04 georgesmith46

Confirm, I got same error right now

thread 'main' panicked at /home/devel/.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 15471, Rope/RopeSlice char length 5070
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace 

kkonevets avatar Apr 15 '25 13:04 kkonevets

I checked with main and the error still happens, but the exact error message changed a bit. Also added RUST_BACKTRACE=1 - backtrace.txt.

I think that the error comes from that it's possible to switch windows while performing the selection. It seems like this is only possible when clicking with the mouse. If I try to switch windows using keyboard shortcuts - Ctrl-w Right ,jump_view_right - then it isn't possible to switch windows without first aborting the selection, and the error doesn't happen.

Seems related to https://github.com/helix-editor/helix/issues/5632

clample avatar May 11 '25 07:05 clample

I'm using 25.07.1 and have encountered the same thing about every few days.

For some reason I could not get the link to the backtrace.txt provided by @clample to work so I decided to share one here in case its helpful.

thread 'main' panicked at /home/slugbyte/.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 3753, Rope/RopeSlice char length 1528
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 as helix_term::compositor::Component>::handle_event
   9: helix_term::compositor::Compositor::handle_event
  10: hx::main_impl::{{closure}}
  11: tokio::runtime::park::CachedParkThread::block_on
  12: tokio::runtime::context::runtime::enter_runtime
  13: tokio::runtime::runtime::Runtime::block_on
  14: hx::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I just set my RUST_BACKTRACE=full and will update ^above if I get something new

slugbyte avatar Oct 31 '25 03:10 slugbyte

@slugbyte Are you able to provide some context of what you were doing when it happened? Are you on linux or mac? Did you have splits? Did you click with a mouse? Did you edit the file externally?

RoloEdits avatar Oct 31 '25 08:10 RoloEdits

@RoloEdits sorry I can't remember too many details... I will add more context if it happens again. I probably had a split open though, I usually have a horizontal split open. All I'm sure of is that I was editing a zig file and I have the zig lsp installed and working with helix, but I'm not sure if that is relevant. I didn't intentinoally edit the file externally (but the lsp might have). I was not using a mouse.

Im on Linux (Fedora 42 x86_64), using ghostty terminal emulator.

slugbyte avatar Oct 31 '25 16:10 slugbyte

Same error for me too

$ hx src/some_file.cpp
thread 'main' panicked at /home/devel/.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 16196, Rope/RopeSlice char length 7335
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Can't reproduce, happened unexpectedly while I pressed g-d, not 100% sure.

UPD: just noticed that I already reported here earlier, sorry guys, looks like it's a frequent bug :)

kkonevets avatar Nov 06 '25 13:11 kkonevets

I ran into this today with 25.07.1 while editing some small files. I'm not sure what the exact trigger was.

markstos avatar Nov 28 '25 00:11 markstos