Skip to content

Commit ac60d58

Browse files
authored
feat(updater): improve tracing and error logging (#2513)
1 parent cb38f54 commit ac60d58

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

.changes/updater-logs.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"updater": patch
3+
"updater-js": patch
4+
---
5+
6+
Enhance error logging.

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/updater/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ tauri = { workspace = true }
3030
serde = { workspace = true }
3131
serde_json = { workspace = true }
3232
thiserror = { workspace = true }
33+
log = { workspace = true }
3334
tokio = "1"
3435
reqwest = { version = "0.12", default-features = false, features = [
3536
"json",

plugins/updater/src/updater.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,14 @@ impl Updater {
371371
.replace("{{arch}}", self.arch)
372372
.parse()?;
373373

374+
log::debug!("checking for updates {url}");
375+
374376
let mut request = ClientBuilder::new().user_agent(UPDATER_USER_AGENT);
375377
if let Some(timeout) = self.timeout {
376378
request = request.timeout(timeout);
377379
}
378380
if let Some(ref proxy) = self.proxy {
381+
log::debug!("using proxy {proxy}");
379382
let proxy = reqwest::Proxy::all(proxy.as_str())?;
380383
request = request.proxy(proxy);
381384
}
@@ -391,24 +394,38 @@ impl Updater {
391394
if res.status().is_success() {
392395
// no updates found!
393396
if StatusCode::NO_CONTENT == res.status() {
397+
log::debug!("update endpoint returned 204 No Content");
394398
return Ok(None);
395399
};
396400

397-
raw_json = Some(res.json().await?);
398-
match serde_json::from_value::<RemoteRelease>(raw_json.clone().unwrap())
401+
let update_response: serde_json::Value = res.json().await?;
402+
log::debug!("update response: {update_response:?}");
403+
raw_json = Some(update_response.clone());
404+
match serde_json::from_value::<RemoteRelease>(update_response)
399405
.map_err(Into::into)
400406
{
401407
Ok(release) => {
408+
println!("parsed release response {release:?}");
402409
last_error = None;
403410
remote_release = Some(release);
404-
// we found a relase, break the loop
411+
// we found a release, break the loop
405412
break;
406413
}
407-
Err(err) => last_error = Some(err),
414+
Err(err) => {
415+
log::error!("failed to deserialize update response: {err}");
416+
last_error = Some(err)
417+
}
408418
}
419+
} else {
420+
log::error!(
421+
"update endpoint did not respond with a successful status code"
422+
);
409423
}
410424
}
411-
Err(err) => last_error = Some(err.into()),
425+
Err(err) => {
426+
log::error!("failed to check for updates: {err}");
427+
last_error = Some(err.into())
428+
}
412429
}
413430
}
414431

@@ -670,6 +687,7 @@ impl Update {
670687
};
671688

672689
if let Some(on_before_exit) = self.on_before_exit.as_ref() {
690+
log::debug!("running on_before_exit hook");
673691
on_before_exit();
674692
}
675693

@@ -838,6 +856,7 @@ impl Update {
838856

839857
#[cfg(feature = "zip")]
840858
if infer::archive::is_gz(bytes) {
859+
log::debug!("extracting AppImage");
841860
// extract the buffer to the tmp_dir
842861
// we extract our signed archive into our final directory without any temp file
843862
let archive = Cursor::new(bytes);
@@ -861,6 +880,7 @@ impl Update {
861880
return Err(Error::BinaryNotFoundInArchive);
862881
}
863882

883+
log::debug!("rewriting AppImage");
864884
return match std::fs::write(&self.extract_path, bytes)
865885
.and_then(|_| std::fs::set_permissions(&self.extract_path, permissions))
866886
{
@@ -914,6 +934,7 @@ impl Update {
914934
fn install_deb(&self, bytes: &[u8]) -> Result<()> {
915935
// First verify the bytes are actually a .deb package
916936
if !infer::archive::is_deb(bytes) {
937+
log::warn!("update is not a valid deb package");
917938
return Err(Error::InvalidUpdaterFormat);
918939
}
919940

@@ -956,13 +977,15 @@ impl Update {
956977
.status()
957978
{
958979
if status.success() {
980+
log::debug!("installed deb with pkexec");
959981
return Ok(());
960982
}
961983
}
962984

963985
// 2. Try zenity or kdialog for a graphical sudo experience
964986
if let Ok(password) = self.get_password_graphically() {
965987
if self.install_with_sudo(deb_path, &password)? {
988+
log::debug!("installed deb with GUI sudo");
966989
return Ok(());
967990
}
968991
}
@@ -975,6 +998,7 @@ impl Update {
975998
.status()?;
976999

9771000
if status.success() {
1001+
log::debug!("installed deb with sudo");
9781002
Ok(())
9791003
} else {
9801004
Err(Error::DebInstallFailed)
@@ -1098,6 +1122,7 @@ impl Update {
10981122
};
10991123

11001124
if need_authorization {
1125+
log::debug!("app installation needs admin privileges");
11011126
// Use AppleScript to perform moves with admin privileges
11021127
let apple_script = format!(
11031128
"do shell script \"rm -rf '{src}' && mv -f '{new}' '{src}'\" with administrator privileges",

0 commit comments

Comments
 (0)