дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 01:57:13 +02:00
fix(updates): keep the cause chain in updater errors (#8285)
The Update check failed notification showed only reqwest's top-level message (error sending request for url …), hiding what failed, such as a refused connection to a manual HTTP proxy that isn't running. ide_http::client::describe now takes any error and follows its sources, and the update check, the pre-download check and the download request/body reads use it. Endpoints, proxy routing and timeouts are unchanged. Co-authored-by: Inf1mum <[email protected]>
Цей коміт міститься в:
1 джерело
bdc4b1ef98
коміт
ca6efe197c
4 files changed
+57
-10
No files matched your search
@@ -174,9 +174,9 @@ pub async fn check_connection(proxy: &ProxySettings, url: &str, cancel: &Cancell
|
||||
Ok(format!("{} {}", status.as_u16(), status.canonical_reason().unwrap_or("")).trim_end().to_owned())
|
||||
}
|
||||
|
||||
/// reqwest errors with their causes ("error sending request: … connection refused").
|
||||
pub fn describe(e: &reqwest::Error) -> String {
|
||||
use std::error::Error;
|
||||
/// An error with its causes ("error sending request: … connection refused"), so
|
||||
/// messages surfaced to the user keep the step that actually failed.
|
||||
pub fn describe(e: &(dyn std::error::Error + 'static)) -> String {
|
||||
let mut msg = e.to_string();
|
||||
let mut source = e.source();
|
||||
while let Some(s) = source {
|
||||
@@ -194,6 +194,51 @@ pub fn describe(e: &reqwest::Error) -> String {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// The updater wraps reqwest in its own error type (`tauri-plugin-updater`'s
|
||||
/// `#[error(transparent)]` variant), so `describe` must follow `source` through
|
||||
/// any error, not just `reqwest::Error`.
|
||||
#[derive(Debug)]
|
||||
struct ConnectRefused;
|
||||
impl std::fmt::Display for ConnectRefused {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "tcp connect error: connection refused 127.0.0.1:55134")
|
||||
}
|
||||
}
|
||||
impl std::error::Error for ConnectRefused {}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct WrappedRequest {
|
||||
source: ConnectRefused,
|
||||
}
|
||||
impl std::fmt::Display for WrappedRequest {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"error sending request for url (https://cnb.cool/l0ng-ai/openidea/-/releases/latest/download/latest.json)"
|
||||
)
|
||||
}
|
||||
}
|
||||
impl std::error::Error for WrappedRequest {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
Some(&self.source)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn describe_keeps_the_causes_behind_a_wrapped_error() {
|
||||
let error = WrappedRequest { source: ConnectRefused };
|
||||
assert_eq!(
|
||||
describe(&error),
|
||||
"error sending request for url (https://cnb.cool/l0ng-ai/openidea/-/releases/latest/download/latest.json): \
|
||||
tcp connect error: connection refused 127.0.0.1:55134"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn describe_of_an_error_without_causes_is_unchanged() {
|
||||
assert_eq!(describe(&ConnectRefused), "tcp connect error: connection refused 127.0.0.1:55134");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn auto_mode_rebuilds_the_shared_client_when_the_system_proxy_changes() {
|
||||
static SYSTEM: Mutex<String> = Mutex::new(String::new());
|
||||
|
||||
@@ -755,7 +755,7 @@ pub(crate) async fn check_update(app: &AppHandle, source: UpdateSource) -> IdeRe
|
||||
let update = tokio::time::timeout(std::time::Duration::from_secs(60), updater.check())
|
||||
.await
|
||||
.map_err(|e| IdeError::unavailable(e.to_string()))?
|
||||
.map_err(|e| IdeError::unavailable(e.to_string()))?;
|
||||
.map_err(|e| IdeError::unavailable(ide_http::client::describe(&e)))?;
|
||||
Ok(UpdateCheck {
|
||||
enabled: true,
|
||||
update: update.map(|u| UpdateInfo {
|
||||
|
||||
@@ -195,10 +195,11 @@ pub(crate) async fn download_update(
|
||||
mut progress: impl FnMut(u64, Option<u64>),
|
||||
) -> IdeResult<DownloadedUpdate> {
|
||||
let updater = updater(app, source)?.ok_or_else(|| IdeError::unavailable("updates are not configured"))?;
|
||||
let update =
|
||||
cancellable(token, async { updater.check().await.map_err(|error| IdeError::unavailable(error.to_string())) })
|
||||
.await?
|
||||
.ok_or_else(|| IdeError::not_found("no update available"))?;
|
||||
let update = cancellable(token, async {
|
||||
updater.check().await.map_err(|error| IdeError::unavailable(ide_http::client::describe(&error)))
|
||||
})
|
||||
.await?
|
||||
.ok_or_else(|| IdeError::not_found("no update available"))?;
|
||||
let directory = app
|
||||
.path()
|
||||
.app_cache_dir()
|
||||
|
||||
@@ -47,7 +47,8 @@ pub(crate) async fn fetch(
|
||||
if offset > 0 {
|
||||
request = request.header(RANGE, format!("bytes={offset}-"));
|
||||
}
|
||||
let response = request.send().await.map_err(|error| IdeError::unavailable(error.to_string()))?;
|
||||
let response =
|
||||
request.send().await.map_err(|error| IdeError::unavailable(ide_http::client::describe(&error)))?;
|
||||
let status = response.status();
|
||||
|
||||
if status == StatusCode::RANGE_NOT_SATISFIABLE && offset > 0 {
|
||||
@@ -171,7 +172,7 @@ async fn append_body(
|
||||
progress(downloaded, total);
|
||||
}
|
||||
Ok(None) => break Ok(()),
|
||||
Err(error) => break Err(IdeError::unavailable(error.to_string())),
|
||||
Err(error) => break Err(IdeError::unavailable(ide_http::client::describe(&error))),
|
||||
}
|
||||
};
|
||||
// tokio writes in the background: flush even when the body broke off, so the bytes
|
||||
|
||||
Reference in new issue
Заблокувати користувача