rust-libp2p icon indicating copy to clipboard operation
rust-libp2p copied to clipboard

chore(libp2p-swarm-test): Add `#[track_caller]` to `SwarmExt` methods

Open ark0f opened this issue 1 year ago • 3 comments

Description

Add #[track_caller] to SwarmExt methods so we can know exactly where panic occurs

Notes & open questions

Change checklist

  • [x] I have performed a self-review of my own code
  • [x] I have made corresponding changes to the documentation
  • [x] I have added tests that prove my fix is effective or that my feature works
  • [x] A changelog entry has been made in the appropriate crates

ark0f avatar Aug 21 '24 19:08 ark0f

Hi, afaiu this shouldn't be necessary as after Rust 1.42 panic! already do it. Can you elaborate why you think this needs to be added and give an example comparing the stack trace with and without these annotations? Thanks

jxs avatar Aug 22 '24 17:08 jxs

Hi.

as after Rust 1.42 panic! already do it.

The example says about the standard library.

The documentation also has minimal example:

  • It prints called from src/main.rs:9:5 (e. g. inside fn main()) by default.
  • If you omit #[track_caller], it will print called from src/main.rs:5:32 (e.g. inside fn print_caller()).

So the same applies to SwarmExt methods. You just see a panic somewhere in libp2p-swarm-test crate but you don't see it in your tests without #[track_caller] attribute.

ark0f avatar Aug 23 '24 20:08 ark0f

Hi.

as after Rust 1.42 panic! already do it.

The example says about the standard library.

The documentation also has minimal example:

  • It prints called from src/main.rs:9:5 (e. g. inside fn main()) by default.
  • If you omit #[track_caller], it will print called from src/main.rs:5:32 (e.g. inside fn print_caller()).

So the same applies to SwarmExt methods. You just see a panic somewhere in libp2p-swarm-test crate but you don't see it in your tests without #[track_caller] attribute.

yeah but that is also achievable setting RUST_BACKTRACE=1 right? The reason I also asked for the stack trace is because https://github.com/rust-lang/rust/issues/87417 and https://github.com/rust-lang/rust/issues/110011 so it seems this won't work

jxs avatar Aug 28 '24 11:08 jxs