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

Panic on a pending inline snapshot when the code moves #220

Closed
max-sixty opened this issue Mar 19, 2022 · 0 comments · Fixed by #221
Closed

Panic on a pending inline snapshot when the code moves #220

max-sixty opened this issue Mar 19, 2022 · 0 comments · Fixed by #221
Labels
bug Something isn't working

Comments

@max-sixty
Copy link
Collaborator

max-sixty commented Mar 19, 2022

What happened?

When there's a pending inline snapshot and the code changes such that the line moves, running cargo insta test panics with:

thread 'main' panicked at 'Could not find snapshot in line 109', /Users/maximilian/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-insta-1.13.0/src/inline.rs:66:21
stack backtrace:
   0:        0x102d73d88 - std::backtrace_rs::backtrace::libunwind::trace::hbad44c2b21d61f40
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:        0x102d73d88 - std::backtrace_rs::backtrace::trace_unsynchronized::h664423984da6366c
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x102d73d88 - std::sys_common::backtrace::_print_fmt::ha0bed729b1de74e6
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/sys_common/backtrace.rs:67:5
   3:        0x102d73d88 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h58c637f9e30d1b8a
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/sys_common/backtrace.rs:46:22
   4:        0x102d93a60 - core::fmt::write::hc16ca97d9f5e0acd
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/fmt/mod.rs:1168:17
   5:        0x102d6f1b8 - std::io::Write::write_fmt::hd53dc7153ccce04d
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/io/mod.rs:1660:15
   6:        0x102d765ec - std::sys_common::backtrace::_print::h52e9a34b49f28ab7
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/sys_common/backtrace.rs:49:5
   7:        0x102d765ec - std::sys_common::backtrace::print::h0bf7306c450cdde6
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/sys_common/backtrace.rs:36:9
   8:        0x102d765ec - std::panicking::default_hook::{{closure}}::ha41f2cf175ca93cf
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:211:50
   9:        0x102d76194 - std::panicking::default_hook::h838498b157804a1a
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:228:9
  10:        0x102d76bb0 - std::panicking::rust_panic_with_hook::h7722806c30430655
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:606:17
  11:        0x102d76920 - std::panicking::begin_panic_handler::{{closure}}::h265229fa7cad6de7
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:502:13
  12:        0x102d74254 - std::sys_common::backtrace::__rust_end_short_backtrace::hfa83d61d0ed14557
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/sys_common/backtrace.rs:139:18
  13:        0x102d76688 - rust_begin_unwind
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
  14:        0x102da6008 - core::panicking::panic_fmt::hd3f68d55261c2af0
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
  15:        0x102b672a4 - cargo_insta::inline::FilePatcher::add_snapshot_macro::h8a79f97c8f49c2fe
  16:        0x102b1da70 - cargo_insta::cargo::SnapshotContainer::load::h274867ffb5783729
  17:        0x102b209c8 - core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut::hfb6e5615a426443f
  18:        0x102b3ab90 - <core::iter::adapters::filter_map::FilterMap<I,F> as core::iter::traits::iterator::Iterator>::next::h183f1bfea2264370
  19:        0x102b311a8 - cargo_insta::cli::load_snapshot_containers::hf409b9dd856c3707
  20:        0x102b31a94 - cargo_insta::cli::process_snapshots::h397828296feac642
  21:        0x102b34210 - cargo_insta::cli::test_run::h9b83dbd1e984526b
  22:        0x102b38acc - cargo_insta::cli::run::h7b33cc41a7ac66db
  23:        0x102b3be9c - cargo_insta::main::hc514b8cc9ffa638d
  24:        0x102b3f3ac - std::sys_common::backtrace::__rust_begin_short_backtrace::h28a0262009a3684a
  25:        0x102b6cbe4 - std::rt::lang_start::{{closure}}::h008ec206a5775c7d
  26:        0x102d73574 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hba09dfad0460fd87
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/ops/function.rs:259:13
  27:        0x102d73574 - std::panicking::try::do_call::h4ce3f7a5c9aef539
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:406:40
  28:        0x102d73574 - std::panicking::try::hd24b5077d4e7cf4f
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:370:19
  29:        0x102d73574 - std::panic::catch_unwind::h7e4545d59021a7e8
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panic.rs:133:14
  30:        0x102d73574 - std::rt::lang_start_internal::{{closure}}::h84dbc49308bdb431
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/rt.rs:128:48
  31:        0x102d73574 - std::panicking::try::do_call::h72e6b5f705f91e0a
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:406:40
  32:        0x102d73574 - std::panicking::try::hb85264d1d4244b1a
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:370:19
  33:        0x102d73574 - std::panic::catch_unwind::h202929673dde26bb
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panic.rs:133:14
  34:        0x102d73574 - std::rt::lang_start_internal::h0c28bd035905a2f7
                               at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/rt.rs:128:20
  35:        0x102b3f460 - _main
[[Command exited with 101]]

I get this quite often since I generally leave on:

RUST_BACKTRACE=1 watchexec -c -e rs,pest -- cargo +nightly insta test --accept

...and so whenever there's a test that doesn't pass, and a snapshot changes, the snapshot stays pending, and adding or removing code which changes a line will then cause a panic.

I realize i haven't been involved much in development since the early days of 0.11.0 (!). But after I've finished the latest version of my current project, I could take this, if no one else does.

Reproduction steps

  1. Write inline test
  2. Run cargo insta test
  3. Before reviewing, add a line to the code such that the inline test changes line
  4. Run cargo insta test

Insta Version

1.13.0

rustc Version

1.59.0

What did you expect?

Probably deleting the out-of-date snapshot, maybe with a warning.

Maaaybe there's a case for an error, I wouldn't advocate for that though.

@max-sixty max-sixty added the bug Something isn't working label Mar 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant