Retrieve app version from crash rather than from current binary
The crash might have been generated weeks before and the app may have been updated since then.
This commit is contained in:
parent
09a8b8e675
commit
54a45095cd
2 changed files with 45 additions and 27 deletions
|
@ -137,7 +137,7 @@ struct Crash {
|
||||||
text: String,
|
text: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument(skip(crash))]
|
||||||
async fn trace_crash(crash: Json<Crash>) -> Result<()> {
|
async fn trace_crash(crash: Json<Crash>) -> Result<()> {
|
||||||
tracing::error!(version = %crash.version, text = %crash.text, "crash report");
|
tracing::error!(version = %crash.version, text = %crash.text, "crash report");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -265,20 +265,38 @@ fn init_crash_handler(
|
||||||
background
|
background
|
||||||
.spawn({
|
.spawn({
|
||||||
let logs_dir_path = logs_dir_path.clone();
|
let logs_dir_path = logs_dir_path.clone();
|
||||||
let app_version = ZED_APP_VERSION.map_or("dev".to_string(), |v| v.to_string());
|
|
||||||
async move {
|
async move {
|
||||||
let crash_report_url = format!("{}/api/crash", &*client::ZED_SERVER_URL);
|
let crash_report_url = format!("{}/api/crash", &*client::ZED_SERVER_URL);
|
||||||
let mut children = smol::fs::read_dir(&logs_dir_path).await?;
|
let mut children = smol::fs::read_dir(&logs_dir_path).await?;
|
||||||
while let Some(child) = children.next().await {
|
while let Some(child) = children.next().await {
|
||||||
let child = child?;
|
let child = child?;
|
||||||
let child_path = child.path();
|
let child_path = child.path();
|
||||||
if child_path.extension() == Some(OsStr::new("crash")) {
|
if child_path.extension() != Some(OsStr::new("crash")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let filename = if let Some(filename) = child_path.file_name() {
|
||||||
|
filename.to_string_lossy()
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut components = filename.split('-');
|
||||||
|
if components.next() != Some("zed") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let version = if let Some(version) = components.next() {
|
||||||
|
version
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
let text = smol::fs::read_to_string(&child_path)
|
let text = smol::fs::read_to_string(&child_path)
|
||||||
.await
|
.await
|
||||||
.context("error reading crash file")?;
|
.context("error reading crash file")?;
|
||||||
let body = serde_json::to_string(&json!({
|
let body = serde_json::to_string(&json!({
|
||||||
"text": text,
|
"text": text,
|
||||||
"version": app_version
|
"version": version
|
||||||
}))
|
}))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let request = Request::builder()
|
let request = Request::builder()
|
||||||
|
@ -296,13 +314,13 @@ fn init_crash_handler(
|
||||||
log::error!("{:?}", response);
|
log::error!("{:?}", response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok::<_, anyhow::Error>(())
|
Ok::<_, anyhow::Error>(())
|
||||||
}
|
}
|
||||||
.log_err()
|
.log_err()
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
|
let app_version = ZED_APP_VERSION.map_or("dev".to_string(), |v| v.to_string());
|
||||||
let is_pty = stdout_is_a_pty();
|
let is_pty = stdout_is_a_pty();
|
||||||
panic::set_hook(Box::new(move |info| {
|
panic::set_hook(Box::new(move |info| {
|
||||||
let backtrace = Backtrace::new();
|
let backtrace = Backtrace::new();
|
||||||
|
@ -335,9 +353,9 @@ fn init_crash_handler(
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
let crash_filename = chrono::Utc::now().format("%Y-%m-%d-%H_%M_%S").to_string();
|
let crash_filename = chrono::Utc::now().format("%Y_%m_%d %H_%M_%S").to_string();
|
||||||
fs::write(
|
fs::write(
|
||||||
logs_dir_path.join(format!("zed-{}.crash", crash_filename)),
|
logs_dir_path.join(format!("zed-{}-{}.crash", app_version, crash_filename)),
|
||||||
&message,
|
&message,
|
||||||
)
|
)
|
||||||
.context("error writing panic to disk")
|
.context("error writing panic to disk")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue