cyfs_debug/bug_report/
request.rs1use crate::panic::CyfsPanicInfo;
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Debug, Serialize, Deserialize)]
5pub struct PanicReportRequest {
6 pub product_name: String,
7 pub service_name: String,
8 pub exe_name: String,
9 pub target: String,
10 pub version: String,
11 pub channel: String,
12
13 pub info: CyfsPanicInfo,
14}
15
16impl PanicReportRequest {
17 pub fn new(product_name: &str, service_name: &str, panic_info: CyfsPanicInfo) -> Self {
18 let exe_name = match std::env::current_exe() {
19 Ok(path) => match path.file_name() {
20 Some(v) => v.to_str().unwrap_or("[unknown]").to_owned(),
21 None => "[unknown]".to_owned(),
22 },
23 Err(_e) => "[unknown]".to_owned(),
24 };
25
26 Self {
27 product_name: product_name.to_owned(),
28 service_name: service_name.to_owned(),
29 exe_name,
30 target: cyfs_base::get_target().to_owned(),
31 version: cyfs_base::get_version().to_owned(),
32 channel: cyfs_base::get_channel().to_string(),
33 info: panic_info,
34 }
35 }
36
37 pub fn to_string(&self) -> String {
38 match serde_json::to_string(&self) {
39 Ok(s) => s,
40 Err(e) => {
41 let msg = format!("encode panic request to string error: {:?}, {}", self, e);
42 error!("{}", msg);
43 msg
44 }
45 }
46 }
47
48 pub fn info_to_string(&self) -> String {
49 match serde_json::to_string(&self.info) {
50 Ok(s) => s,
51 Err(e) => {
52 let msg = format!("encode panic info to string error: {:?}, {}", self.info, e);
53 error!("{}", msg);
54 msg
55 }
56 }
57 }
58}