Skip to content

Panic when processing diff file with only file renames. #24

@psandana

Description

@psandana

Description
Generating a diff file with git:

git diff origin/main.. | Tee-Object diff.out

Generates the following output:

diff --git a/crate/examples/example1.rs b/crate/examples/example_renamed1.rs
similarity index 100%
rename from crate/examples/example1.rs
rename to /crate/examples/example_renamed1.rs

The code is panicking on:

stack backtrace:
   0:     0x7ff699b03aa2 - std::sys_common::backtrace::_print::impl$0::fmt
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\std\src\sys_common\backtrace.rs:44
   1:     0x7ff699b279cd - core::fmt::rt::Argument::fmt
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\core\src\fmt\rt.rs:142
   2:     0x7ff699b279cd - core::fmt::write
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\core\src\fmt\mod.rs:1120
   3:     0x7ff699aff6a1 - std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\std\src\io\mod.rs:1810
   4:     0x7ff699b038ca - std::sys_common::backtrace::_print
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\std\src\sys_common\backtrace.rs:47
   5:     0x7ff699b038ca - std::sys_common::backtrace::print
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\std\src\sys_common\backtrace.rs:34
   6:     0x7ff699b06029 - std::panicking::default_hook::closure$1
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\std\src\panicking.rs:272
   7:     0x7ff699b05ce5 - std::panicking::default_hook
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\std\src\panicking.rs:292
   8:     0x7ff699b06554 - std::panicking::rust_panic_with_hook
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\std\src\panicking.rs:779
   9:     0x7ff699b06429 - std::panicking::begin_panic_handler::closure$0
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\std\src\panicking.rs:657
  10:     0x7ff699b043a9 - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\std\src\sys_common\backtrace.rs:171
  11:     0x7ff699b060f2 - std::panicking::begin_panic_handler
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\std\src\panicking.rs:645
  12:     0x7ff699b32547 - core::panicking::panic_fmt
                               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library\core\src\panicking.rs:72
  13:     0x7ff6995678da - patch::parser::parse_multiple_patches
                               at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\patch-0.7.0\src\parser.rs:84
  14:     0x7ff6995672fb - patch::ast::Patch::from_multiple
                               at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\patch-0.7.0\src\ast.rs:134
  15:     0x7ff6991a0641 - cargo_mutants::in_diff::diff_filter
                               at C:\open-src\cargo-mutants\src\in_diff.rs:23
  16:     0x7ff699136a25 - cargo_mutants::main

I was using cargo mutants, but this is reproducible by using patch too. patch::parser::patch is not processing errors from the interior, which are valid: Not finding the --- tags because diff is only renames.

Ask
Add error checks to gracefully handle cases when there is no changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions