tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[feat] Capture and display all errors, even if Tauri cannot resolve them

Open Think-M opened this issue 7 months ago • 3 comments

Describe the problem

I have encountered multiple instances of applications crashing inexplicably. After such an issue occurred, no relevant information was found in the. log file, and only the relevant Application Error (exception code 0xc0000005) could be seen in the Windows Event Viewer. There was no useful information other than that, such as #11356 . This greatly hinders the reproduction and investigation of the problem.

Describe the solution you'd like

Rust does a good job in error handling and passing. Is it possible to capture all possible errors and prompt them through MessageBox or similar obvious ways?

Alternatives considered

No response

Additional context

No response

Think-M avatar May 21 '25 11:05 Think-M

To me, I did something like this in my app, and the crash would be shown in the log file tauri_plugin_log created

let default_panic = std::panic::take_hook();
std::panic::set_hook(Box::new(move |info| {
    let backtrace = Backtrace::force_capture();
    log::error!("Panic: {info}\n{backtrace}");
    default_panic(info);
}));

Legend-Master avatar May 22 '25 01:05 Legend-Master

To me, I did something like this in my app, and the crash would be shown in the log file tauri_plugin_log created对我来说,我在我的应用程序中做了类似的事情,并且崩溃将显示在创建的日志文件中

let default_panic = std::panic::take_hook(); std::panic::set_hook(Box::new(move |info| { let backtrace = Backtrace::force_capture(); log::error!("Panic: {info}\n{backtrace}"); default_panic(info); }));

@Legend-Master Thank you. Is this code placed in the following location?

tauri::Builder::default().setup(|app| {
    let default_panic = std::panic::take_hook();
    std::panic::set_hook(Box::new(move |info| {
        let backtrace = Backtrace::force_capture();
        log::error! ("Panic: {info}\n{backtrace}");
        default_panic(info);
    }));
    ...

Think-M avatar May 22 '25 08:05 Think-M

I'll just put it at the beginning of the main function, but this is fine as well

Legend-Master avatar May 22 '25 08:05 Legend-Master