Open qarmin opened 4 months ago
👍 That hard line break causes that panic situation. Haven't had time to dig deeper into what causes this. black formatted is not able to parse the file. However ruff formatter is able to handle this and after the formatting, it will not panic.
I'm getting the following when trying to fix the file (ruff cli):
panicked at crates/ruff_python_trivia/src/textwrap.rs:172:52:
byte index 18446744073709551604 is out of bounds of `\
Update: The problem is, as indicated in the backtrace:
panicked at crates/ruff_python_trivia/src/textwrap.rs:155:22: attempt to subtract with overflow
that we try to unsafe subtraction, and therefore Rust panics with overflow error. However, the calling function (dedent_to, textwrap.rs) indicates that it panics in the following case:
/// # Panics
/// If the first line is indented by less than the provided indent.
pub fn dedent_to(text: &str, indent: &str) -> String {
Instead of panicking, we should cleanly shut down with a proper error message.
The problem occurs on the following line (155) in ruff/crates/ruff_python_trivia/src/textwrap.rs
:
let dedent_len = existing_indent_len - indent.len();
Here some debug prints about the used variables:
INPUT TEXT: "\\\n Branch = hv.streams.Stream.define(\"branch\", branch=None)"
INDENT: " "
EXISTING INDENT LEN: 0
INDENT LEN: 12
Still panics with ruff 0.4.6
file content:
def has_untracted_files():
if b'Untracked files' in result.stdout:
return True
else:
\
return False
error
All checks passed!
error: Panicked while linting /home/rafal/test/tmp_folder/284806655513326825.py: This indicates a bug in Ruff. If you could open an issue at:
https://github.com/astral-sh/ruff/issues/new?title=%5BLinter%20panic%5D
...with the relevant file contents, the `pyproject.toml` settings, and the following stack trace, we'd be very appreciative!
panicked at crates/ruff_python_trivia/src/textwrap.rs:172:52:
byte index 18446744073709551612 is out of bounds of `\
`
Backtrace: 0: ruff::panic::catch_unwind::{{closure}}
1: std::panicking::rust_panic_with_hook
2: std::panicking::begin_panic_handler::{{closure}}
3: std::sys_common::backtrace::__rust_end_short_backtrace
4: rust_begin_unwind
5: core::panicking::panic_fmt
6: core::str::slice_error_fail_rt
7: core::str::slice_error_fail
8: ruff_python_trivia::textwrap::dedent_to
9: ruff_linter::fix::edits::adjust_indentation
10: ruff_linter::rules::flake8_return::rules::function::remove_else
11: ruff_linter::checkers::ast::analyze::statement::statement
12: <ruff_linter::checkers::ast::Checker as ruff_python_ast::visitor::Visitor>::visit_stmt
13: ruff_linter::checkers::ast::check_ast
14: ruff_linter::linter::check_path
15: ruff_linter::linter::lint_fix
16: ruff::diagnostics::lint_path
17: ruff::commands::check::lint_path
18: rayon::iter::plumbing::Producer::fold_with
19: rayon::iter::plumbing::bridge_producer_consumer::helper
20: ruff::commands::check::check
21: ruff::check
22: ruff::run
23: ruff::main
24: std::sys_common::backtrace::__rust_begin_short_backtrace
25: std::rt::lang_start::{{closure}}
26: std::rt::lang_start_internal
27: main
28: __libc_start_call_main
at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
29: __libc_start_main_impl
at ./csu/../csu/libc-start.c:360:3
30: _start
ruff 0.2.2 (also happens with 0.3.5) (latest changes from main branch)
file content:
error
python_compressed.zip