Better error handling for SSH (#19533)

Before this change we sometimes showed errors inline, sometimes in
alerts.
Sometimes we closed the window, someimtes we didn't.

Now they always show as prompts and we never close windows.

Co-Authored-By: Mikayla <mikayla@zed.dev>

Release Notes:

- SSH Remoting: Improve error handling
This commit is contained in:
Conrad Irwin 2024-10-21 23:17:42 -06:00 committed by GitHub
parent 6e485453d0
commit 4f52077d97
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 107 additions and 136 deletions

View file

@ -233,7 +233,6 @@ pub trait SshClientDelegate: Send + Sync {
cx: &mut AsyncAppContext,
) -> oneshot::Receiver<Result<(PathBuf, SemanticVersion)>>;
fn set_status(&self, status: Option<&str>, cx: &mut AsyncAppContext);
fn set_error(&self, error_message: String, cx: &mut AsyncAppContext);
}
impl SshSocket {
@ -485,7 +484,6 @@ impl SshRemoteClient {
if let Err(error) = client.ping(HEARTBEAT_TIMEOUT).await {
log::error!("failed to establish connection: {}", error);
delegate.set_error(error.to_string(), &mut cx);
return Err(error);
}
@ -1301,9 +1299,7 @@ impl SshRemoteConnection {
};
if let Err(e) = result {
let error_message = format!("Failed to connect to host: {}.", e);
delegate.set_error(error_message, cx);
return Err(e);
return Err(e.context("Failed to connect to host"));
}
drop(askpass_task);
@ -1317,7 +1313,6 @@ impl SshRemoteConnection {
"failed to connect: {}",
String::from_utf8_lossy(&output).trim()
);
delegate.set_error(error_message.clone(), cx);
Err(anyhow!(error_message))?;
}
@ -1862,8 +1857,5 @@ mod fake {
fn set_status(&self, _: Option<&str>, _: &mut AsyncAppContext) {
unreachable!()
}
fn set_error(&self, _: String, _: &mut AsyncAppContext) {
unreachable!()
}
}
}