Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

client: Format the whole error chain on failure to connect to Cloud (#59035)

Tom Houlé7220d880d19a
diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs
index 1d6524ec7f4..2c8dfa8ba47 100644
--- a/crates/client/src/client.rs
+++ b/crates/client/src/client.rs
@@ -971,7 +971,7 @@ impl Client {
Ok(valid) => Ok(valid),
Err(err) => {
self.set_status(Status::AuthenticationError, cx);
- Err(anyhow!("failed to validate credentials: {}", err))
+ Err(err.context("failed to validate credentials"))
}
}
}
@@ -2242,6 +2242,45 @@ mod tests {
assert_eq!(credentials.access_token, "2");
}
+ #[gpui::test]
+ async fn test_sign_in_reports_connection_failure(cx: &mut TestAppContext) {
+ init_test(cx);
+ let http_client = FakeHttpClient::create(|_request| async move {
+ Ok(http_client::Response::builder()
+ .status(200)
+ .body("".into())
+ .unwrap())
+ });
+ let client =
+ cx.update(|cx| Client::new(Arc::new(FakeSystemClock::new()), http_client.clone(), cx));
+ client.override_authenticate(move |cx| {
+ cx.background_spawn(async move {
+ Ok(Credentials {
+ user_id: 1,
+ access_token: "token".into(),
+ })
+ })
+ });
+
+ // Sign in once so that the credentials are cached on the client.
+ client.sign_in(false, &cx.to_async()).await.unwrap();
+
+ // Simulate a transport-level failure (DNS/TCP/TLS/timeout) where the
+ // request never receives a response while validating cached credentials.
+ http_client
+ .as_fake()
+ .replace_handler(|_, _request| async move {
+ Err(anyhow!("connection reset by peer").context("boom"))
+ });
+
+ let error = client.sign_in(false, &cx.to_async()).await.unwrap_err();
+
+ assert_eq!(
+ format!("{error:#}"),
+ "failed to validate credentials: boom: connection reset by peer"
+ );
+ }
+
#[gpui::test(iterations = 10)]
async fn test_authenticating_more_than_once(
cx: &mut TestAppContext,