spacedriveapp / spacedrive

Spacedrive is an open source cross-platform file explorer, powered by a virtual distributed filesystem written in Rust.
https://spacedrive.com
GNU Affero General Public License v3.0
29.33k stars 835 forks source link

Display captured backtrace when available #2504

Closed matheus-consoli closed 3 weeks ago

matheus-consoli commented 1 month ago

Tries to capture and display the backtrace when the system crashes.

Note tho, that in the current state, it seems that tauri is somehow messing with the backtrace, so if the core crashes, it only captures an empty backtrace - I'm still not sure why, and I will investigate more later.

But with this added code, we at least start capturing the stacktrace, and when we figure out the tauri issue or move the core to a daemon architecture, it will emit the stacktrace.

As an example, if we create core/src/bin/a.rs:

use sd_core::Node;

fn main() {
    let _guard = Node::init_logger("./").unwrap();
    panic!("ops");
}

and run the application RUST_BACKTRACE=1 cargo run, it will emit the backtrace:

Collapsed ```sh 2024-05-24T16:53:29.496031Z ERROR sd_core: core/src/lib.rs:243: panicked at core/src/bin/backtrace.rs:5:5: ops panic.file="core/src/bin/backtrace.rs:5" panic.column=5 2024-05-24T16:53:29.500813Z ERROR sd_core: core/src/lib.rs:252: 0: sd_core::Node::init_logger::{{closure}} 1: as core::ops::function::Fn>::call at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/boxed.rs:2034:9 2: std::panicking::rust_panic_with_hook at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:783:13 3: std::panicking::begin_panic_handler::{{closure}} at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:649:13 4: std::sys_common::backtrace::__rust_end_short_backtrace at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/sys_common/backtrace.rs:171:18 5: rust_begin_unwind at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:645:5 6: core::panicking::panic_fmt at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:72:14 7: backtrace::main 8: core::ops::function::FnOnce::call_once 9: std::sys_common::backtrace::__rust_begin_short_backtrace 10: std::rt::lang_start::{{closure}} 11: core::ops::function::impls:: for &F>::call_once at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/ops/function.rs:284:13 12: std::panicking::try::do_call at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:552:40 13: std::panicking::try at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:516:19 14: std::panic::catch_unwind at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panic.rs:146:14 15: std::rt::lang_start_internal::{{closure}} at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/rt.rs:148:48 16: std::panicking::try::do_call at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:552:40 17: std::panicking::try at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:516:19 18: std::panic::catch_unwind at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panic.rs:146:14 19: std::rt::lang_start_internal at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/rt.rs:148:20 20: std::rt::lang_start 21: main 22: 23: __libc_start_main 24: _start ```
vercel[bot] commented 1 month ago

@matheus-consoli is attempting to deploy a commit to the Spacedrive Team on Vercel.

A member of the Team first needs to authorize it.