difftastic icon indicating copy to clipboard operation
difftastic copied to clipboard

thread 'main' panicked at 'Hunk lines should be present in matched lines', src/display/hunks.rs:663:23

Open Adamkadaban opened this issue 1 year ago • 3 comments

Panic in display/hunks.rs

Files: 1.txt 2.txt

image

thread 'main' panicked at 'Hunk lines should be present in matched lines', src/display/hunks.rs:663:23
stack backtrace:
   0:     0x56481b1cb5b5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb070b7fa7e3175df
   1:     0x56481b01c23e - core::fmt::write::hd5207aebbb9a86e9
   2:     0x56481b1c7b05 - std::io::Write::write_fmt::h3bd699bbd129ab8a
   3:     0x56481b1ccd23 - std::panicking::default_hook::{{closure}}::h04cca40023d0eeca
   4:     0x56481b1cca2f - std::panicking::default_hook::haa3ca8c310ed5402
   5:     0x56481b1cd34c - std::panicking::rust_panic_with_hook::h7b190ce1a948faac
   6:     0x56481b1cd254 - std::panicking::begin_panic_handler::{{closure}}::hbafbfdc3e1b97f68
   7:     0x56481b1cbabc - std::sys_common::backtrace::__rust_end_short_backtrace::hda93e5fef243b4c0
   8:     0x56481b1ccfa2 - rust_begin_unwind
   9:     0x56481af7c793 - core::panicking::panic_fmt::h8d17ca1073d9a733
  10:     0x56481b01ace1 - core::panicking::panic_display::he956d1fbfe1d4c76
  11:     0x56481b01ac8b - core::panicking::panic_str::h7d5968eea59d06d2
  12:     0x56481af7c606 - core::option::expect_failed::h03d502d0855ade10
  13:     0x56481b089b96 - difft::display::hunks::matched_lines_indexes_for_hunk::h4b77df964d62e4c9
  14:     0x56481b07a891 - difft::display::side_by_side::print::h5d49acdfd78f8219
  15:     0x56481b03e06b - difft::print_diff_result::hbab8ebae5e039c47
  16:     0x56481b039f54 - difft::main::h829b432de9803b7e
  17:     0x56481b046203 - std::sys_common::backtrace::__rust_begin_short_backtrace::h1cf47cf43a9e9613
  18:     0x56481b08cdb9 - std::rt::lang_start::{{closure}}::hfa91847e2be1747f
  19:     0x56481b1c180a - std::rt::lang_start_internal::h6ba1bb743c1e9df9
  20:     0x56481b03e728 - main
  21:     0x7fcd62d4724a - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  22:     0x7fcd62d47305 - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:360:3
  23:     0x56481af9781e - _start
  24:                0x0 - <unknown>

Version: Difftastic 0.60.0 (1ac9553 2024-07-30, built with rustc 1.65.0) Downloaded from releases

Adamkadaban avatar Oct 03 '24 06:10 Adamkadaban

I'm unsure if this was the case when I first submitted the issue, but it seems this now only happens with one order of the files image

thread 'main' panicked at 'Hunk lines should be present in matched lines', src/display/hunks.rs:663:23
stack backtrace:
   0:     0x55bb9f96fd15 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3155a8c966b4beb5
   1:     0x55bb9f7bf23e - core::fmt::write::h062c617411b691df
   2:     0x55bb9f96c8d5 - std::io::Write::write_fmt::hb61fdf1275c61e1c
   3:     0x55bb9f96fae5 - std::sys_common::backtrace::print::hca896ae22beb06cb
   4:     0x55bb9f9712bf - std::panicking::default_hook::{{closure}}::h0b5eeed5cf36ab5f
   5:     0x55bb9f97102a - std::panicking::default_hook::h8932b573145a321b
   6:     0x55bb9f97192f - std::panicking::rust_panic_with_hook::h4b1447a24e3e94f8
   7:     0x55bb9f9716e4 - std::panicking::begin_panic_handler::{{closure}}::h8701da9995a3820c
   8:     0x55bb9f97021c - std::sys_common::backtrace::__rust_end_short_backtrace::hb696c5ed02a01598
   9:     0x55bb9f971432 - rust_begin_unwind
  10:     0x55bb9f71c5c3 - core::panicking::panic_fmt::h8aa706a976963c88
  11:     0x55bb9f7bdce1 - core::panicking::panic_display::h145080b539a57164
  12:     0x55bb9f7bdc8b - core::panicking::panic_str::hb7f52c873200464f
  13:     0x55bb9f71c586 - core::option::expect_failed::hf416ac71eef81151
  14:     0x55bb9f82f3c6 - difft::display::hunks::matched_lines_indexes_for_hunk::h9f9e2aa738126b7f
  15:     0x55bb9f820044 - difft::display::side_by_side::print::h9b8d9ae36adfd23d
  16:     0x55bb9f7e109b - difft::print_diff_result::h8899cf4ba00640da
  17:     0x55bb9f7dd01e - difft::main::h2b7829dd9e2a2a59
  18:     0x55bb9f7e94f3 - std::sys_common::backtrace::__rust_begin_short_backtrace::he7f7716f7442975a
  19:     0x55bb9f840d39 - std::rt::lang_start::{{closure}}::hfde1be8a0e006cca
  20:     0x55bb9f965fd8 - std::rt::lang_start_internal::hcd7e45acd25ab5ab
  21:     0x55bb9f7e1755 - main
  22:     0x7fdf7104624a - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  23:     0x7fdf71046305 - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:360:3
  24:     0x55bb9f73a18e - _start
  25:                0x0 - <unknown>

Adamkadaban avatar Oct 30 '24 06:10 Adamkadaban

same

jarjk avatar Nov 21 '24 14:11 jarjk

Haven't fully tested, but these changes work for my usecase (and seem to past all the testcases in the repo)

diff --git a/src/display/hunks.rs b/src/display/hunks.rs
index 06187393a..19cb82ff4 100644
--- a/src/display/hunks.rs
+++ b/src/display/hunks.rs
@@ -660,8 +660,11 @@ pub(crate) fn matched_lines_indexes_for_hunk(
         }
     }
 
-    let mut start_i = start_i.expect("Hunk lines should be present in matched lines");
-    let mut end_i = end_i.expect("Hunk lines should be present in matched lines");
+    // If start_i or end_i is None, it means the hunk lines weren't found in matched_lines.
+    // This can happen when one side of the diff has no novel content.
+    // In that case, use the start or end of matched_lines
+    let mut start_i = start_i.unwrap_or(0);
+    let mut end_i = end_i.unwrap_or(matched_lines.len());
     if start_i >= num_context_lines {
         start_i -= num_context_lines;
     } else {

Adamkadaban avatar May 13 '25 05:05 Adamkadaban