From cc055901e1b530c80a73eb5f98ba1572064c77bd Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Thu, 1 Jun 2023 23:34:39 -0400 Subject: [PATCH] Add additional panic information to panic events --- crates/feedback/src/system_specs.rs | 2 ++ crates/zed/src/main.rs | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/crates/feedback/src/system_specs.rs b/crates/feedback/src/system_specs.rs index b6eb6e8b6d..48955a8629 100644 --- a/crates/feedback/src/system_specs.rs +++ b/crates/feedback/src/system_specs.rs @@ -6,6 +6,8 @@ use std::{env, fmt::Display}; use sysinfo::{System, SystemExt}; use util::channel::ReleaseChannel; +// TODO: Move this file out of feedback and into a more general place + #[derive(Clone, Debug, Serialize)] pub struct SystemSpecs { #[serde(serialize_with = "serialize_app_version")] diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 9ec3e3d3f6..4b0661c6e6 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -70,10 +70,7 @@ fn main() { log::info!("========== starting zed =========="); let mut app = gpui::App::new(Assets).unwrap(); - let app_version = ZED_APP_VERSION - .or_else(|| app.platform().app_version().ok()) - .map_or("dev".to_string(), |v| v.to_string()); - init_panic_hook(app_version); + init_panic_hook(&app); app.background(); @@ -376,19 +373,29 @@ struct Panic { backtrace: Vec, // TODO // stripped_backtrace: String, + release_channel: String, + os_name: String, + os_version: Option, + architecture: String, time: u128, } #[derive(Serialize)] struct PanicRequest { panic: Panic, + // TODO: Move to Panic struct, as app_version - requires changing zed.dev version: String, token: String, } -fn init_panic_hook(app_version: String) { +fn init_panic_hook(app: &App) { let is_pty = stdout_is_a_pty(); + let platform = app.platform(); + panic::set_hook(Box::new(move |info| { + let app_version = ZED_APP_VERSION + .or_else(|| platform.app_version().ok()) + .map_or("dev".to_string(), |v| v.to_string()); let backtrace = Backtrace::new(); let thread = thread::current(); @@ -414,6 +421,13 @@ fn init_panic_hook(app_version: String) { .map(|line| line.to_string()) .collect(), // modified_backtrace: None, + release_channel: RELEASE_CHANNEL.dev_name().into(), + os_name: platform.os_name().into(), + os_version: platform + .os_version() + .ok() + .map(|os_version| os_version.to_string()), + architecture: env::consts::ARCH.into(), time: SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap()