-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
"thread panicked while panicking. aborting." when panicking in display trait, which is utilized in panic #97181
Comments
When run through use std::fmt::{Display, self};
struct MyStruct;
impl Display for MyStruct {
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
todo!()
}
}
fn main() {
let instance = MyStruct;
assert!(false, "oh no, '{}' was unexpected", instance);
} The full panic message and backtrace for the second panic is printed: Output
I think when run as a test, the panic output is captured (as normal for a test), but is then not printed because of the abort. @rustbot label -A-diagnostics -T-compiler +A-libtest (I'm not sure what the correct team assignment for this is...) |
The output capturing mechanism has code to try to prevent capturing output from a double-panic: rust/library/std/src/io/stdio.rs Lines 996 to 1013 in c067287
But the panic message is actually written into a string first: rust/library/std/src/panicking.rs Lines 543 to 554 in c067287
|
@SNCPlay42
That doesn't happen anymore, with rust 1.75.0, it seems to be a regression, all I get is what the playground shows, even with rust nightly with RUST_BACKTRACE on:
so, no stack trace. The actual double panic stacktrace is inside that rust/library/std/src/panicking.rs Line 778 in 03994e4
click me to expand contentsthread panicked while processing panic. aborting. msg='Some(not yet implemented)' loc='Location { file: "/home/user/sandbox/rust/05_sandbox/tests/ri97181/src/main.rs", line: 7, col: 9 }'
0: std::panicking::rust_panic_with_hook
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:751:32
1: std::panicking::begin_panic_handler::{{closure}}
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:649:13
2: std::sys_common::backtrace::__rust_end_short_backtrace
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:170:18
3: rust_begin_unwind
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5
4: core::panicking::panic_fmt
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14
5: core::panicking::panic
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:127:5
6: <ri97181::MyStruct as core::fmt::Display>::fmt
at ./src/main.rs:7:9
7: core::fmt::rt::Argument::fmt
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/fmt/rt.rs:142:9
8: core::fmt::write
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/fmt/mod.rs:1120:17
9: <&mut W as core::fmt::Write::write_fmt::SpecWriteFmt>::spec_write_fmt
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/fmt/mod.rs:211:17
10: core::fmt::Write::write_fmt
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/fmt/mod.rs:215:14
11: std::panicking::begin_panic_handler::FormatStringPayload::fill::{{closure}}
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:611:30
12: core::option::Option<T>::get_or_insert_with
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/option.rs:1663:26
13: std::panicking::begin_panic_handler::FormatStringPayload::fill
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:609:13
14: <std::panicking::begin_panic_handler::FormatStringPayload as core::panic::PanicPayload>::get
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:627:13
15: std::panicking::rust_panic_with_hook
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:787:19
16: std::panicking::begin_panic_handler::{{closure}}
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:657:13
17: std::sys_common::backtrace::__rust_end_short_backtrace
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:170:18
18: rust_begin_unwind
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5
19: core::panicking::panic_fmt
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14
20: ri97181::main
at ./src/main.rs:14:5
21: core::ops::function::FnOnce::call_once
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
22: std::sys_common::backtrace::__rust_begin_short_backtrace
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/sys_common/backtrace.rs:154:18
23: std::rt::lang_start::{{closure}}
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/rt.rs:167:18
24: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:284:13
25: std::panicking::try::do_call
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:552:40
26: std::panicking::try
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:516:19
27: std::panic::catch_unwind
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs:142:14
28: std::rt::lang_start_internal::{{closure}}
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/rt.rs:148:48
29: std::panicking::try::do_call
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:552:40
30: std::panicking::try
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:516:19
31: std::panic::catch_unwind
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panic.rs:142:14
32: std::rt::lang_start_internal
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/rt.rs:148:20
33: std::rt::lang_start
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/rt.rs:166:17
34: main
35: __libc_start_call_main
at /usr/src/debug/sys-libs/glibc-2.39-r2/glibc-2.39/csu/../sysdeps/nptl/libc_start_call_main.h:58:16
36: __libc_start_main_impl
at /usr/src/debug/sys-libs/glibc-2.39-r2/glibc-2.39/csu/../csu/libc-start.c:360:3
37: _start but to get the above output, I had to use a rust patch: Index: /var/tmp/portage/dev-lang/rust-1.75.0-r1/work/rustc-1.75.0-src/library/std/src/panicking.rs
===================================================================
--- .orig/var/tmp/portage/dev-lang/rust-1.75.0-r1/work/rustc-1.75.0-src/library/std/src/panicking.rs
+++ /var/tmp/portage/dev-lang/rust-1.75.0-r1/work/rustc-1.75.0-src/library/std/src/panicking.rs
@@ -746,9 +747,11 @@ fn rust_panic_with_hook(
panic_count::MustAbort::PanicInHook => {
// Don't try to print the message in this case
// - perhaps that is causing the recursive panics.
- rtprintpanic!("thread panicked while processing panic. aborting.\n");
+ rtprintpanic!("thread panicked while processing panic. aborting. msg='{:?}' loc='{:?}'\n",message, location);
+ println!("{}", crate::backtrace::Backtrace::force_capture());
}
panic_count::MustAbort::AlwaysAbort => {
+ println!("in panic_count::MustAbort::AlwaysAbort");
// Unfortunately, this does not print a backtrace, because creating
// a `Backtrace` will allocate, which we must to avoid here.
let panicinfo = PanicInfo::internal_constructor(
Is it a regression ? Or am I missing something here. EDIT: Also, this means, it doesn't get to execute a potential user-set panic hook. EDIT2: I've confirmed that indeed the stacktrace is shown with
EDIT4: first glance appears to be #110975 but I'll try to double check. |
Yeah indeed, today even in
which is pretty barren. Not sure if it would make sense to try and catch panics during message formatting, and then still print a backtrace but without a message, or so. That may be what @Amanieu suggested here; I am not entirely sure. |
Rollup merge of rust-lang#122930 - RalfJung:panic-in-panic-fmt, r=Amanieu add panic location to 'panicked while processing panic' Fixes rust-lang#97181 r? `@Amanieu`
add panic location to 'panicked while processing panic' Fixes rust-lang/rust#97181 r? `@Amanieu`
…nieu add panic location to 'panicked while processing panic' Fixes rust-lang#97181 r? `@Amanieu`
The following occurs when running the tests
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=35f64605807f3e34fd6a5cb1e650677c
When the tests are ran, the current output is:
After figuring out what the actual issue is, the error message makes sense. But my debugging journey would have been more pleasant, if the source location of the panics were included in the message. Much like the location of "non-nested" panics are printed.
Ideally the output should look like:
At least include the source location of the "inner" panic, or ideally both.
It also suggests to rerun pass with '--lib', which is a bit misleading.
If above is not possible, at least print the name of the test that is failing.
The text was updated successfully, but these errors were encountered: