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

Update to the new backtrace API #124

Closed
wants to merge 2 commits into from

Conversation

thenorili
Copy link
Contributor

This addresses Issue #97. Pardon the half-baked commit message for now, I'll write it out more thoroughly once it's ready. I wrote a minimal test that produces error and panic backtraces, where I'm struggling is capturing this output and comparing it to a snippet. Comparing an error backtrace seems really difficult without intercepting stderr with something like Gag, which I'd prefer to avoid. Comparing the panic backtrace seems promising but the panic hook I added is only sending me the actual panic text -- ie panic!("foo") -> foo.

trying for an error backtrace like..

    fn low(frame: FailFrame) -> Result<(), Report> {
        let e: Report = eyre!("This program's frameness is suspect!");
        if let FailFrame::Low = frame {
            Err::<(), Report>(e).wrap_err("The low-level code has failed!")
            //            panic!("hello");
            //            ()
        } else {
            Ok(())
        }
    }

            Box::new(move |info| {
                let mut global_buffer = global_buffer.lock().unwrap();

                if let Some(s) = info.payload().downcast_ref::<&str>() {
                    println!("PANIC: {}", *s);
                    *global_buffer = (*s).to_string()
                } else {
                    panic!("help!");
                }
            })
        });

        panic::catch_unwind(|| {
            high(FailFrame::Low).unwrap();
        })
        .expect_err("Backtrace test did not panic.");

returns "panicked while processing panic", aka the payload downcast returned None.

@thenorili
Copy link
Contributor Author

comparison to a test working normally:

    #[cfg_attr(not(backtrace), ignore)]
    #[test]
    fn test_backtrace_simple() {
        high(FailFrame::Low).unwrap();
    }

produces

running 1 test
thread 'test_backtrace::test_backtrace_simple' panicked at eyre\tests\test_backtrace.rs:61:30:
called `Result::unwrap()` on an `Err` value: The low-level code has failed!

Caused by:
    This program's frameness is suspect!

Location:
    eyre\tests\test_backtrace.rs:14:25

Stack backtrace:
   0: std::backtrace_rs::backtrace::dbghelp::trace
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\..\..\backtrace\src\backtrace\dbghelp.rs:95
   1: std::backtrace_rs::backtrace::trace_unsynchronized
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2: std::backtrace::Backtrace::create
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\backtrace.rs:331
   3: std::backtrace::Backtrace::capture
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\backtrace.rs:297
   4: eyre::DefaultHandler::default_with
             at .\src\lib.rs:762
   5: core::ops::function::Fn::call<alloc::boxed::Box<dyn$<eyre::EyreHandler>,alloc::alloc::Global> (*)(ref$<dyn$<core::error::Error> >),tuple$<ref$<dyn$<core::error::Error> > > >
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef\library\core\src\ops\function.rs:79
   6: eyre::capture_handler
             at .\src\lib.rs:597
   7: eyre::Report::from_adhoc<ref$<str$> >
             at .\src\error.rs:114
   8: eyre::Report::msg<ref$<str$> >
             at .\src\error.rs:70
   9: eyre::private::format_err
             at .\src\lib.rs:1229
  10: test_backtrace::test_backtrace::low
             at .\tests\test_backtrace.rs:14
  11: test_backtrace::test_backtrace::med
             at .\tests\test_backtrace.rs:29
  12: test_backtrace::test_backtrace::high
             at .\tests\test_backtrace.rs:37
  13: test_backtrace::test_backtrace::test_backtrace_simple
             at .\tests\test_backtrace.rs:61
  14: test_backtrace::test_backtrace::test_backtrace_simple::closure$0
             at .\tests\test_backtrace.rs:60
  15: core::ops::function::FnOnce::call_once<test_backtrace::test_backtrace::test_backtrace_simple::closure_env$0,tuple$<> >
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef\library\core\src\ops\function.rs:250
  16: core::ops::function::FnOnce::call_once
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\core\src\ops\function.rs:250
  17: test::__rust_begin_short_backtrace<enum2$<core::result::Result<tuple$<>,alloc::string::String> >,enum2$<core::result::Result<tuple$<>,alloc::string::String> > (*)()>
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\test\src\lib.rs:628
  18: test::run_test_in_process::closure$0
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\test\src\lib.rs:651
  19: core::panic::unwind_safe::impl$23::call_once
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\core\src\panic\unwind_safe.rs:272
  20: std::panicking::try::do_call
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panicking.rs:552
  21: std::panicking::try
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panicking.rs:516
  22: std::panic::catch_unwind
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panic.rs:142
  23: test::run_test_in_process
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\test\src\lib.rs:651
  24: test::run_test::closure$0
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\test\src\lib.rs:574
  25: test::run_test::closure$1
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\test\src\lib.rs:602
  26: std::sys_common::backtrace::__rust_begin_short_backtrace<test::run_test::closure_env$1,tuple$<> >
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\sys_common\backtrace.rs:154
  27: std::thread::impl$0::spawn_unchecked_::closure$1::closure$0
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\thread\mod.rs:529
  28: core::panic::unwind_safe::impl$23::call_once
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\core\src\panic\unwind_safe.rs:272
  29: std::panicking::try::do_call
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panicking.rs:552
  30: std::panicking::try
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panicking.rs:516
  31: std::panic::catch_unwind
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panic.rs:142
  32: std::thread::impl$0::spawn_unchecked_::closure$1
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\thread\mod.rs:528
  33: core::ops::function::FnOnce::call_once<std::thread::impl$0::spawn_unchecked_::closure_env$1<test::run_test::closure_env$1,tuple$<> >,tuple$<> >
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\core\src\ops\function.rs:250
  34: std::sys::windows::thread::impl$0::new::thread_start
             at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\sys\windows\thread.rs:58
  35: BaseThreadInitThunk
  36: RtlUserThreadStart

stack backtrace:
   0:     0x7ff6a5377cf3 - std::sys_common::backtrace::_print::impl$0::fmt
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\sys_common\backtrace.rs:44
   1:     0x7ff6a539615d - core::fmt::rt::Argument::fmt
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\core\src\fmt\rt.rs:142
   2:     0x7ff6a539615d - core::fmt::write
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\core\src\fmt\mod.rs:1117
   3:     0x7ff6a53741b1 - std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\io\mod.rs:1763
   4:     0x7ff6a5377afa - std::sys_common::backtrace::_print
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\sys_common\backtrace.rs:47
   5:     0x7ff6a5377afa - std::sys_common::backtrace::print
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\sys_common\backtrace.rs:34
   6:     0x7ff6a537a639 - std::panicking::default_hook::closure$1
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panicking.rs:272
   7:     0x7ff6a537a2fb - std::panicking::default_hook
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panicking.rs:292
   8:     0x7ff6a537ab24 - std::panicking::rust_panic_with_hook
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panicking.rs:779
   9:     0x7ff6a537a9f5 - std::panicking::begin_panic_handler::closure$0
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panicking.rs:657
  10:     0x7ff6a53785e9 - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>      
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\sys_common\backtrace.rs:170
  11:     0x7ff6a537a704 - std::panicking::begin_panic_handler
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panicking.rs:645
  12:     0x7ff6a53a0577 - core::panicking::panic_fmt
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\core\src\panicking.rs:72
  13:     0x7ff6a53a0af3 - core::result::unwrap_failed
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\core\src\result.rs:1653
  14:     0x7ff6a53135f0 - enum2$<core::result::Result<tuple$<>,eyre::Report> >::unwrap<tuple$<>,eyre::Report>
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef\library\core\src\result.rs:1077
  15:     0x7ff6a5312ad1 - test_backtrace::test_backtrace::test_backtrace_simple
                               at C:\Users\nori\dev\eyre\eyre\tests\test_backtrace.rs:61
  16:     0x7ff6a53136c8 - test_backtrace::test_backtrace::test_backtrace_simple::closure$0
                               at C:\Users\nori\dev\eyre\eyre\tests\test_backtrace.rs:60
  17:     0x7ff6a5311052 - core::ops::function::FnOnce::call_once<test_backtrace::test_backtrace::test_backtrace_simple::closure_env$0,tuple$<> > 
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef\library\core\src\ops\function.rs:250
  18:     0x7ff6a53560df - core::ops::function::FnOnce::call_once
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\core\src\ops\function.rs:250
  19:     0x7ff6a53560df - test::__rust_begin_short_backtrace<enum2$<core::result::Result<tuple$<>,alloc::string::String> >,enum2$<core::result::Result<tuple$<>,alloc::string::String> > (*)()>
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\test\src\lib.rs:628
  20:     0x7ff6a5354b53 - test::run_test_in_process::closure$0
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\test\src\lib.rs:651
  21:     0x7ff6a5354b53 - core::panic::unwind_safe::impl$23::call_once
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\core\src\panic\unwind_safe.rs:272
  22:     0x7ff6a5354b53 - std::panicking::try::do_call
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panicking.rs:552
  23:     0x7ff6a5354b53 - std::panicking::try
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panicking.rs:516
  24:     0x7ff6a5354b53 - std::panic::catch_unwind
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panic.rs:142
  25:     0x7ff6a5354b53 - test::run_test_in_process
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\test\src\lib.rs:651
  26:     0x7ff6a5354b53 - test::run_test::closure$0
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\test\src\lib.rs:574
  27:     0x7ff6a5313b6a - test::run_test::closure$1
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\test\src\lib.rs:602
  28:     0x7ff6a5313b6a - std::sys_common::backtrace::__rust_begin_short_backtrace<test::run_test::closure_env$1,tuple$<> >
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\sys_common\backtrace.rs:154
  29:     0x7ff6a53196b0 - std::thread::impl$0::spawn_unchecked_::closure$1::closure$0
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\thread\mod.rs:529
  30:     0x7ff6a53196b0 - core::panic::unwind_safe::impl$23::call_once
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\core\src\panic\unwind_safe.rs:272
  31:     0x7ff6a53196b0 - std::panicking::try::do_call
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panicking.rs:552
  32:     0x7ff6a53196b0 - std::panicking::try
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panicking.rs:516
  33:     0x7ff6a53196b0 - std::panic::catch_unwind
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\panic.rs:142
  34:     0x7ff6a53196b0 - std::thread::impl$0::spawn_unchecked_::closure$1
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\thread\mod.rs:528
  35:     0x7ff6a53196b0 - core::ops::function::FnOnce::call_once<std::thread::impl$0::spawn_unchecked_::closure_env$1<test::run_test::closure_env$1,tuple$<> >,tuple$<> >
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\core\src\ops\function.rs:250
  36:     0x7ff6a538682c - std::sys::windows::thread::impl$0::new::thread_start
                               at /rustc/4b85902b438f791c5bfcb6b1c5b476d5b88e2bef/library\std\src\sys\windows\thread.rs:58
  37:     0x7ffcfc36257d - BaseThreadInitThunk
  38:     0x7ffcfd38aa58 - RtlUserThreadStart
test test_backtrace::test_backtrace_simple ... FAILED

failures:

failures:
    test_backtrace::test_backtrace_simple

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.05s

error: test failed, to rerun pass `-p eyre --test test_backtrace`

@thenorili
Copy link
Contributor Author

Even if I set up gag to grab the output during this panic, I don't see how to keep getting that output with a panic handler that's been modified not to panic so that I can go on to test the output. I'm going to look at how std backtrace writes their unit tests.

@thenorili thenorili force-pushed the 97-2-issue branch 2 times, most recently from 7bb9083 to 68a2624 Compare November 20, 2023 07:50
@thenorili thenorili self-assigned this Nov 25, 2023
@thenorili
Copy link
Contributor Author

We fixed backtrace in #160 and determined that the UI test isn't a realistic goal.

@thenorili thenorili closed this Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant