aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-10-19 13:35:03 -0400
committerJesse Luehrs <doy@tozt.net>2019-10-19 13:35:03 -0400
commit22f743a73062819c76a5cab3503aee52f884ce79 (patch)
tree0f37e44b86e9f2c1c6a67ee72b3ad54ee90b2975
parentf42f8d325273ff4d387c966c8cdb57b0bf92d3e8 (diff)
downloadteleterm-22f743a73062819c76a5cab3503aee52f884ce79.tar.gz
teleterm-22f743a73062819c76a5cab3503aee52f884ce79.zip
display connection errors in the watch ui
-rw-r--r--src/client.rs21
-rw-r--r--src/cmd/watch.rs16
-rw-r--r--src/error.rs2
3 files changed, 31 insertions, 8 deletions
diff --git a/src/client.rs b/src/client.rs
index 80a7455..fc9c07a 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -96,6 +96,8 @@ pub struct Client<
on_login: Vec<crate::protocol::Message>,
to_send: std::collections::VecDeque<crate::protocol::Message>,
+
+ last_error: Option<String>,
}
impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
@@ -164,6 +166,8 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
on_login: on_login.to_vec(),
to_send: std::collections::VecDeque::new(),
+
+ last_error: None,
}
}
@@ -176,6 +180,10 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
self.wsock = WriteSocket::NotConnected;
}
+ pub fn last_error(&self) -> Option<&str> {
+ self.last_error.as_ref().map(std::string::String::as_str)
+ }
+
fn set_reconnect_timer(&mut self) {
let delay = rand::thread_rng().gen_range(
self.reconnect_backoff_amount / 2,
@@ -269,6 +277,7 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
for msg in &self.on_login {
self.to_send.push_back(msg.clone());
}
+ self.last_error = None;
Ok((
crate::component_future::Async::Ready(Some(
Event::Connect,
@@ -421,8 +430,10 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
Err(e) => {
log::warn!("error while connecting, reconnecting: {}", e);
self.reconnect();
- // not sending a disconnect event here because we never
- // actually connected, so it'd just be spammy
+ self.last_error = Some(format!("{}", e));
+ return Ok(crate::component_future::Async::Ready(Some(
+ Event::Disconnect,
+ )));
}
},
WriteSocket::Connected(..) | WriteSocket::Writing(..) => {
@@ -433,6 +444,8 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
"haven't seen server in a while, reconnecting",
);
self.reconnect();
+ self.last_error =
+ Some("haven't seen server in a while".to_string());
return Ok(crate::component_future::Async::Ready(Some(
Event::Disconnect,
)));
@@ -480,6 +493,7 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
e
);
self.reconnect();
+ self.last_error = Some(format!("{}", e));
Ok(crate::component_future::Async::Ready(Some(
Event::Disconnect,
)))
@@ -492,6 +506,7 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
Err(e) => {
log::warn!("error reading message, reconnecting: {}", e);
self.reconnect();
+ self.last_error = Some(format!("{}", e));
Ok(crate::component_future::Async::Ready(Some(
Event::Disconnect,
)))
@@ -519,6 +534,7 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
e
);
self.reconnect();
+ self.last_error = Some(format!("{}", e));
Ok(crate::component_future::Async::Ready(Some(
Event::Disconnect,
)))
@@ -564,6 +580,7 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
Err(e) => {
log::warn!("error writing message, reconnecting: {}", e);
self.reconnect();
+ self.last_error = Some(format!("{}", e));
Ok(crate::component_future::Async::Ready(Some(
Event::Disconnect,
)))
diff --git a/src/cmd/watch.rs b/src/cmd/watch.rs
index 284fc0e..31cd505 100644
--- a/src/cmd/watch.rs
+++ b/src/cmd/watch.rs
@@ -443,11 +443,17 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static>
crossterm::terminal()
.clear(crossterm::ClearType::All)
.context(crate::error::WriteTerminalCrossterm)?;
- let data = b"loading...\r\nq: quit --> ";
- let stdout = std::io::stdout();
- let mut stdout = stdout.lock();
- stdout.write(data).context(crate::error::WriteTerminal)?;
- stdout.flush().context(crate::error::FlushTerminal)?;
+
+ println!("loading...\r");
+ if let Some(err) = self.list_client.last_error() {
+ println!("error: {}\r", err);
+ }
+ print!("q: quit --> ");
+
+ std::io::stdout()
+ .flush()
+ .context(crate::error::FlushTerminal)?;
+
Ok(())
}
diff --git a/src/error.rs b/src/error.rs
index 7a3f226..eab1c78 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -50,7 +50,7 @@ pub enum Error {
source: tokio::io::Error,
},
- #[snafu(display("eof"))]
+ #[snafu(display("received EOF from server"))]
EOF,
#[snafu(display("failed to retrieve access token: {:?}", msg))]