MCPcopy Create free account
hub / github.com/VSCodeConfigHelper/v4 / send_error

Function send_error

src-tauri/src/tasks/statistics.rs:60–93  ·  view source on GitHub ↗

如果启用了日志发送,返回标识码

(e: &Error)

Source from the content-addressed store, hash-verified

58
59/// 如果启用了日志发送,返回标识码
60pub fn send_error(e: &Error) -> Option<u64> {
61 error!("错误:{:?}", e);
62 if !*ENABLED.lock().unwrap() {
63 return None;
64 }
65 match (|| -> Result<u64> {
66 let mut id = hardware_id::get_id()
67 .map(|id| {
68 debug!("本机硬件 ID {}", id);
69 let mut s = DefaultHasher::new();
70 id.hash(&mut s);
71 s.finish()
72 })
73 .unwrap_or_else(|_| rand::random());
74 id %= 1_000_000;
75 warn!("发送错误日志。标识码 {}", id);
76 let res = reqwest::blocking::Client::new()
77 .post(format!("https://api.guyutongxue.site/vscch/errorLog/{}", id))
78 .header(CONTENT_TYPE, "text/plain")
79 .body(fs::read_to_string(get_log_path())?)
80 .send()?;
81 if res.status().is_success() {
82 Ok(id)
83 } else {
84 Err(anyhow!(res.text()?))
85 }
86 })() {
87 Err(e) => {
88 error!("发送错误日志时出错:{:?}", e);
89 None
90 }
91 Ok(id) => Some(id),
92 }
93}

Callers 2

task_initFunction · 0.85
gui_handledFunction · 0.85

Calls 1

get_log_pathFunction · 0.85

Tested by

no test coverage detected