From 609d7ceb7a2ffbcff288e0e000db57a6da9162ae Mon Sep 17 00:00:00 2001 From: ardocrat Date: Fri, 20 Sep 2024 14:45:40 +0300 Subject: [PATCH] build: remove panic message dependency --- Cargo.lock | 7 ------- Cargo.toml | 1 - src/main.rs | 16 +++++++++++++++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8ce58ec..92b714c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3847,7 +3847,6 @@ dependencies = [ "nokhwa", "openpnp_capture_sys", "openssl-sys", - "panic-message", "parking_lot 0.12.3", "qrcode", "qrcodegen", @@ -6587,12 +6586,6 @@ dependencies = [ "sha2 0.10.8", ] -[[package]] -name = "panic-message" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384e52fd8fbd4cbe3c317e8216260c21a0f9134de108cea8a4dd4e7e152c472d" - [[package]] name = "parking" version = "2.2.0" diff --git a/Cargo.toml b/Cargo.toml index d026157..2815d45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,7 +52,6 @@ rust-i18n = "2.3.1" ## other backtrace = "0.3" -panic-message = "0.3.0" thiserror = "1.0.58" futures = "0.3" dirs = "5.0.1" diff --git a/src/main.rs b/src/main.rs index a51b407..e7123c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,7 +48,7 @@ fn real_main() { let time = grim::gui::views::View::format_time(chrono::Utc::now().timestamp()); let target = egui::os::OperatingSystem::from_target_os(); let ver = grim::VERSION; - let msg = panic_message::panic_info_message(info); + let msg = panic_info_message(info); let err = format!("{} - {:?} - v{}\n\n{}\n\n{:?}", time, target, ver, msg, backtrace); // Save backtrace to file. let log = grim::Settings::crash_report_path(); @@ -76,6 +76,20 @@ fn real_main() { } } +/// Get panic message from crash payload. +fn panic_info_message<'pi>(panic_info: &'pi std::panic::PanicInfo<'_>) -> &'pi str { + let payload = panic_info.payload(); + // taken from: https://github.com/rust-lang/rust/blob/4b9f4b221b92193c7e95b1beb502c6eb32c3b613/library/std/src/panicking.rs#L194-L200 + match payload.downcast_ref::<&'static str>() { + Some(msg) => *msg, + None => match payload.downcast_ref::() { + Some(msg) => msg.as_str(), + // Copy what rustc does in the default panic handler + None => "Box", + }, + } +} + /// Start GUI with Desktop related setup passing data from opening. #[allow(dead_code)] #[cfg(not(target_os = "android"))]