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

thread 'main' panicked at 'byte index 90 is not a char boundary; it is inside 'ó' (bytes 89..91) of `(); #6501

Closed
norman784 opened this issue Mar 31, 2023 · 10 comments
Labels
C-bug Category: This is a bug

Comments

@norman784
Copy link
Contributor

Summary

It seems that there's an issue editing (it seems with svelte files) with special characters, the error in question is:

thread 'main' panicked at 'byte index 90 is not a char boundary; it is inside 'ó' (bytes 89..91) of `();

Reproduction Steps

I tried this:

  1. hx
  2. Edit a file with special character text, in this case I have a word with ó.
  3. It crash

I expected this to happen:

Instead, this happened:

thread 'main' panicked at 'byte index 90 is not a char boundary; it is inside 'ó' (bytes 89..91) of `();

Helix log

~/.cache/helix/helix.log
2023-03-31T17:09:38.014 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":9,"line":3},"start":{"character":9,"line":3}},"text":"l"}],"textDocument":{"uri":"file:///path/to/file.svelte","version":9}}}
2023-03-31T17:09:38.017 helix_view::document [DEBUG] id 2 modified - last saved: 0, current: 0
2023-03-31T17:09:38.088 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":10,"line":3},"start":{"character":10,"line":3}},"text":"e"}],"textDocument":{"uri":"file:///path/to/file.svelte","version":10}}}
2023-03-31T17:09:38.090 helix_view::document [DEBUG] id 2 modified - last saved: 0, current: 0
2023-03-31T17:09:38.141 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":11,"line":3},"start":{"character":11,"line":3}},"text":"t"}],"textDocument":{"uri":"file:///path/to/file.svelte","version":11}}}
2023-03-31T17:09:38.142 helix_view::document [DEBUG] id 2 modified - last saved: 0, current: 0
2023-03-31T17:09:38.231 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":12,"line":3},"start":{"character":12,"line":3}},"text":" "}],"textDocument":{"uri":"file:///path/to/file.svelte","version":12}}}
2023-03-31T17:09:38.233 helix_view::document [DEBUG] id 2 modified - last saved: 0, current: 0
2023-03-31T17:09:38.370 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":13,"line":3},"start":{"character":13,"line":3}},"text":"o"}],"textDocument":{"uri":"file:///path/to/file.svelte","version":13}}}
2023-03-31T17:09:38.372 helix_view::document [DEBUG] id 2 modified - last saved: 0, current: 0
2023-03-31T17:09:38.461 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":14,"line":3},"start":{"character":14,"line":3}},"text":"p"}],"textDocument":{"uri":"file:///path/to/file.svelte","version":14}}}
2023-03-31T17:09:38.463 helix_view::document [DEBUG] id 2 modified - last saved: 0, current: 0
2023-03-31T17:09:38.506 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":15,"line":3},"start":{"character":15,"line":3}},"text":"t"}],"textDocument":{"uri":"file:///path/to/file.svelte","version":15}}}
2023-03-31T17:09:38.507 helix_view::document [DEBUG] id 2 modified - last saved: 0, current: 0
2023-03-31T17:09:38.618 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":16,"line":3},"start":{"character":16,"line":3}},"text":"i"}],"textDocument":{"uri":"file:///path/to/file.svelte","version":16}}}
2023-03-31T17:09:38.621 helix_view::document [DEBUG] id 2 modified - last saved: 0, current: 0
2023-03-31T17:09:38.648 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":17,"line":3},"start":{"character":17,"line":3}},"text":"o"}],"textDocument":{"uri":"file:///path/to/file.svelte","version":17}}}
2023-03-31T17:09:38.649 helix_view::document [DEBUG] id 2 modified - last saved: 0, current: 0
2023-03-31T17:09:38.792 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":18,"line":3},"start":{"character":18,"line":3}},"text":"n"}],"textDocument":{"uri":"file:///path/to/file.svelte","version":18}}}
2023-03-31T17:09:38.795 helix_view::document [DEBUG] id 2 modified - last saved: 0, current: 0
2023-03-31T17:09:38.916 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":19,"line":3},"start":{"character":19,"line":3}},"text":"s"}],"textDocument":{"uri":"file:///path/to/file.svelte","version":19}}}
2023-03-31T17:09:38.919 helix_view::document [DEBUG] id 2 modified - last saved: 0, current: 0
RUST_BACKTRACE=1 hx -vv
helix-core/src/syntax.rs:1232:25
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::str::slice_error_fail_rt
   3: core::str::slice_error_fail
   4: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
   5: tree_sitter::Parser::parse_with::read
   6: _ts_lexer_start
   7: _ts_parser_parse
   8: helix_core::syntax::LanguageLayer::parse
   9: std::thread::local::LocalKey<T>::with
  10: helix_core::syntax::Syntax::update
  11: helix_view::document::Document::apply_impl
  12: helix_view::document::Document::apply
  13: helix_term::commands::insert::insert_char
  14: helix_term::ui::editor::EditorView::insert_mode
  15: <helix_term::ui::editor::EditorView as helix_term::compositor::Component>::handle_event
  16: helix_term::compositor::Compositor::handle_event
  17: hx::main_impl::{{closure}}
  18: tokio::runtime::context::BlockingRegionGuard::block_on
  19: tokio::runtime::runtime::Runtime::block_on
  20: hx::main

Platform

macOs

Terminal Emulator

warp v0.2023.03.21.08.02.stable_02

Helix Version

helix 23.03 (3cf0372)

@norman784 norman784 added the C-bug Category: This is a bug label Mar 31, 2023
@the-mikedavis
Copy link
Member

Can you narrow down the reproduction steps? I can't reproduce this just editing around in a file with :lang svelte.

This looks like some interaction between the tree-sitter parser for svelte and getting characters out of the rope.

@pascalkuthe
Copy link
Member

The issue seems to be that the rope doesn't hand out raw byte references but str which must always be valid utf-8 and therefore can't be split inside a codepoint. It looks like TS just wants raw bytes and could very well split a codepoint (in this case it's a non-ascii char). I don't see them promising anywhere that they will stick to char boundaries. This might an upstream addition ropey tough to be able to retrieve raw bytes without utf-8 checks

@poliorcetics
Copy link
Contributor

Seems similar to a bug I've been having a lot with rust-analyzer:

2023-04-27T11:03:05.475 helix_lsp::transport [ERROR] err <- "Panic context:\n"
2023-04-27T11:03:05.475 helix_lsp::transport [ERROR] err <- "> \n"
2023-04-27T11:03:05.476 helix_lsp::transport [ERROR] err <- "version: 0.0.0 (237ffa399 2023-04-27)\n"
2023-04-27T11:03:05.476 helix_lsp::transport [ERROR] err <- "notification: textDocument/didChange\n"
2023-04-27T11:03:05.476 helix_lsp::transport [ERROR] err <- "\n"
2023-04-27T11:03:05.476 helix_lsp::transport [ERROR] err <- "thread 'LspServer' panicked at 'assertion failed: self.is_char_boundary(n)', /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/string.rs:1819:29\n"
2023-04-27T11:03:05.476 helix_lsp::transport [ERROR] err <- "stack backtrace:\n"
2023-04-27T11:03:05.515 helix_lsp::transport [ERROR] err <- "   0: rust_begin_unwind\n"
2023-04-27T11:03:05.515 helix_lsp::transport [ERROR] err <- "             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:579:5\n"
2023-04-27T11:03:05.515 helix_lsp::transport [ERROR] err <- "   1: core::panicking::panic_fmt\n"
2023-04-27T11:03:05.515 helix_lsp::transport [ERROR] err <- "             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64:14\n"
2023-04-27T11:03:05.515 helix_lsp::transport [ERROR] err <- "   2: core::panicking::panic\n"
2023-04-27T11:03:05.515 helix_lsp::transport [ERROR] err <- "             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:114:5\n"
2023-04-27T11:03:05.515 helix_lsp::transport [ERROR] err <- "   3: alloc::string::String::replace_range\n"
2023-04-27T11:03:05.516 helix_lsp::transport [ERROR] err <- "   4: rust_analyzer::lsp_utils::apply_document_changes\n"
2023-04-27T11:03:05.516 helix_lsp::transport [ERROR] err <- "   5: core::ops::function::FnOnce::call_once\n"
2023-04-27T11:03:05.516 helix_lsp::transport [ERROR] err <- "   6: rust_analyzer::dispatch::NotificationDispatcher::on\n"
2023-04-27T11:03:05.516 helix_lsp::transport [ERROR] err <- "   7: rust_analyzer::main_loop::<impl rust_analyzer::global_state::GlobalState>::run\n"
2023-04-27T11:03:05.516 helix_lsp::transport [ERROR] err <- "   8: rust_analyzer::main_loop::main_loop\n"
2023-04-27T11:03:05.516 helix_lsp::transport [ERROR] err <- "   9: rust_analyzer::run_server\n"
2023-04-27T11:03:05.516 helix_lsp::transport [ERROR] err <- "note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.\n"
2023-04-27T11:03:05.516 helix_lsp::transport [ERROR] err <- "thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: \"SendError(..)\"', lib/lsp-server/src/stdio.rs:26:37\n"
2023-04-27T11:03:05.516 helix_lsp::transport [ERROR] err <- "stack backtrace:\n"
2023-04-27T11:03:05.516 helix_lsp::transport [ERROR] err <- "   0: rust_begin_unwind\n"
2023-04-27T11:03:05.516 helix_lsp::transport [ERROR] err <- "             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:579:5\n"
2023-04-27T11:03:05.516 helix_lsp::transport [ERROR] err <- "   1: core::panicking::panic_fmt\n"
2023-04-27T11:03:05.516 helix_lsp::transport [ERROR] err <- "             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64:14\n"
2023-04-27T11:03:05.516 helix_lsp::transport [ERROR] err <- "   2: core::result::unwrap_failed\n"
2023-04-27T11:03:05.516 helix_lsp::transport [ERROR] err <- "             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/result.rs:1750:5\n"
2023-04-27T11:03:05.516 helix_lsp::transport [ERROR] err <- "note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.\n"

@mmaslyukov
Copy link

mmaslyukov commented May 3, 2023

This bug is easily reproducible on Windows machine and present in helix 23.03 (3cf0372).
To reproduce, add printf!(r#""#) and put inside "" any UTF-8 characters inside or delete (D) already present o UTF-8 characters. In my case, I was adding Cyrillic letters to get the crash.

@pascalkuthe
Copy link
Member

pascalkuthe commented May 3, 2023

I am pretty sure that this has been fixed on master by #6921. I am not able to reproduce the LSP crashes on the later master (while they are reproducible on 23.3). However, I am not able to reproduce an actual panic/crash (on 23.3). I think if I tried hard enough I could. I already managed to make it send an invalid autcompletion range which can lead to similar crash if using more non-utf8 chars. The issue is that usually the server crashes before I manage to make it send something to crash the editor. However I can think of many ways that this issue could cause a panic. Therefore I am pretty sure it's the same issue and I am closing this.

If a similar bug reoccurs on the latest master feel free to reopen/open a new issue.

@happysalada
Copy link
Contributor

happysalada commented May 7, 2023

I am on master and can confirm this is not fixed.
I'm having trouble making a reproducible example (If I ever do, I will make sure to post the repo here. I thought I had one, but as soon as I commited the change and tried to reproduce, it didn't crash anymore).
the latest error message I get is a little different though.

thread 'main' panicked at 'byte_slice(): Byte range does not align with char boundaries: range 745..746', /private/tmp/nix-build-helix-term-0.6.0.drv-0/nix-vendor/ropey-1.6.0/src/slice.rs:703:23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This is also happening for me with svelte files, and the frequency is about once every hour or so.
(Just to put this in context, I think helix is amazing, and I am so grateful for the efforts that everyone is putting into this.).

@happysalada
Copy link
Contributor

@pascalkuthe would you mind if we re-opened the issue or do you want me to create a new one ?

@gabydd
Copy link
Member

gabydd commented May 8, 2023

Seems similar to #3283

@happysalada
Copy link
Contributor

Ah youre right, no need to open a new issue.

@AndyJado
Copy link

thread 'main' panicked at 'byte index 198 is not a char boundary; it is inside '之' (bytes 196..199) of `一些中文`[...]', /Users/andyjado/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/unicode-segmentation-1.10.1/src/grapheme.rs:553:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I met this and it's quite reproducable in the context, then I delete something and save and restore and repeat and I couldn't reproduce it..

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

8 participants