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