-
Notifications
You must be signed in to change notification settings - Fork 431
feat(updater): improve tracing and error logging #2513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"updater": patch | ||
"updater-js": patch | ||
--- | ||
|
||
Enhance error logging. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -371,11 +371,14 @@ impl Updater { | |
.replace("{{arch}}", self.arch) | ||
.parse()?; | ||
|
||
log::debug!("checking for updates {url}"); | ||
|
||
let mut request = ClientBuilder::new().user_agent(UPDATER_USER_AGENT); | ||
if let Some(timeout) = self.timeout { | ||
request = request.timeout(timeout); | ||
} | ||
if let Some(ref proxy) = self.proxy { | ||
log::debug!("using proxy {proxy}"); | ||
let proxy = reqwest::Proxy::all(proxy.as_str())?; | ||
request = request.proxy(proxy); | ||
} | ||
|
@@ -391,24 +394,38 @@ impl Updater { | |
if res.status().is_success() { | ||
// no updates found! | ||
if StatusCode::NO_CONTENT == res.status() { | ||
log::debug!("update endpoint returned 204 No Content"); | ||
return Ok(None); | ||
}; | ||
|
||
raw_json = Some(res.json().await?); | ||
match serde_json::from_value::<RemoteRelease>(raw_json.clone().unwrap()) | ||
let update_response: serde_json::Value = res.json().await?; | ||
log::debug!("update response: {update_response:?}"); | ||
raw_json = Some(update_response.clone()); | ||
match serde_json::from_value::<RemoteRelease>(update_response) | ||
.map_err(Into::into) | ||
{ | ||
Ok(release) => { | ||
println!("parsed release response {release:?}"); | ||
last_error = None; | ||
remote_release = Some(release); | ||
// we found a relase, break the loop | ||
// we found a release, break the loop | ||
break; | ||
} | ||
Err(err) => last_error = Some(err), | ||
Err(err) => { | ||
log::error!("failed to deserialize update response: {err}"); | ||
last_error = Some(err) | ||
} | ||
} | ||
} else { | ||
log::error!( | ||
"update endpoint did not respond with a successful status code" | ||
); | ||
Comment on lines
+420
to
+422
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this case missing a Users are reporting that 400 errors are shown as "invalid json", even though the response should be hitting this success status check, and the body is still a valid json string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like it |
||
} | ||
} | ||
Err(err) => last_error = Some(err.into()), | ||
Err(err) => { | ||
log::error!("failed to check for updates: {err}"); | ||
last_error = Some(err.into()) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -670,6 +687,7 @@ impl Update { | |
}; | ||
|
||
if let Some(on_before_exit) = self.on_before_exit.as_ref() { | ||
log::debug!("running on_before_exit hook"); | ||
on_before_exit(); | ||
} | ||
|
||
|
@@ -838,6 +856,7 @@ impl Update { | |
|
||
#[cfg(feature = "zip")] | ||
if infer::archive::is_gz(bytes) { | ||
log::debug!("extracting AppImage"); | ||
// extract the buffer to the tmp_dir | ||
// we extract our signed archive into our final directory without any temp file | ||
let archive = Cursor::new(bytes); | ||
|
@@ -861,6 +880,7 @@ impl Update { | |
return Err(Error::BinaryNotFoundInArchive); | ||
} | ||
|
||
log::debug!("rewriting AppImage"); | ||
return match std::fs::write(&self.extract_path, bytes) | ||
.and_then(|_| std::fs::set_permissions(&self.extract_path, permissions)) | ||
{ | ||
|
@@ -914,6 +934,7 @@ impl Update { | |
fn install_deb(&self, bytes: &[u8]) -> Result<()> { | ||
// First verify the bytes are actually a .deb package | ||
if !infer::archive::is_deb(bytes) { | ||
log::warn!("update is not a valid deb package"); | ||
return Err(Error::InvalidUpdaterFormat); | ||
} | ||
|
||
|
@@ -956,13 +977,15 @@ impl Update { | |
.status() | ||
{ | ||
if status.success() { | ||
log::debug!("installed deb with pkexec"); | ||
return Ok(()); | ||
} | ||
} | ||
|
||
// 2. Try zenity or kdialog for a graphical sudo experience | ||
if let Ok(password) = self.get_password_graphically() { | ||
if self.install_with_sudo(deb_path, &password)? { | ||
log::debug!("installed deb with GUI sudo"); | ||
return Ok(()); | ||
} | ||
} | ||
|
@@ -975,6 +998,7 @@ impl Update { | |
.status()?; | ||
|
||
if status.success() { | ||
log::debug!("installed deb with sudo"); | ||
Ok(()) | ||
} else { | ||
Err(Error::DebInstallFailed) | ||
|
@@ -1098,6 +1122,7 @@ impl Update { | |
}; | ||
|
||
if need_authorization { | ||
log::debug!("app installation needs admin privileges"); | ||
// Use AppleScript to perform moves with admin privileges | ||
let apple_script = format!( | ||
"do shell script \"rm -rf '{src}' && mv -f '{new}' '{src}'\" with administrator privileges", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
log::debug
as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohhh