From 837a112a50607396377d0c33539255dd840fa64c Mon Sep 17 00:00:00 2001 From: Dhghomon <56599343+Dhghomon@users.noreply.github.com> Date: Wed, 1 Nov 2023 11:38:29 +0900 Subject: [PATCH 1/2] +hint when authentication fails, rv interactive --- src/connect.rs | 34 +++++++++++++++++++--------------- src/repl.rs | 2 +- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/connect.rs b/src/connect.rs index 537148406..632c83fd1 100644 --- a/src/connect.rs +++ b/src/connect.rs @@ -8,7 +8,7 @@ use bytes::Bytes; use tokio::time::sleep; use tokio_stream::Stream; -use edgedb_errors::{Error, ErrorKind, ResultExt}; +use edgedb_errors::{Error, ErrorKind, ResultExt, AuthenticationError}; use edgedb_errors::{NoDataError, ProtocolEncodingError, ClientError}; use edgedb_protocol::QueryResult; use edgedb_protocol::client_message::{State, CompilationOptions}; @@ -151,18 +151,14 @@ impl Connector { self } pub async fn connect(&self) -> Result { - self._connect(false).await + self._connect().await } - pub async fn connect_interactive(&self) -> Result { - self._connect(true).await - } - - async fn _connect(&self, interactive: bool) -> Result { + async fn _connect(&self) -> Result { let cfg = self.config.as_ref().map_err(Clone::clone)?; let conn = tokio::select!( conn = Connection::connect(&cfg) => conn?, - _ = self.print_warning(cfg, interactive) => unreachable!(), + _ = self.print_warning(cfg) => unreachable!(), ); Ok(conn) } @@ -179,16 +175,12 @@ impl Connector { format!("Connecting to {}...", desc) } - async fn print_warning(&self, cfg: &Config, interactive: bool) + async fn print_warning(&self, cfg: &Config) -> Result { sleep(Duration::new(1, 0)).await; let msg = self.warning_msg(cfg); - if interactive { - eprint!("{}", msg); - } else { - eprintln!("{}", msg); - } + eprintln!("{}", msg); pending().await } pub fn get(&self) -> anyhow::Result<&Config, ArcError> { @@ -198,8 +190,20 @@ impl Connector { impl Connection { pub async fn connect(cfg: &Config) -> Result { + let connection = match raw::Connection::connect(&cfg).await { + Ok(conn) => conn, + Err(err) => { + if err.is::() { + eprintln!("Failed to authenticate.\ + \nHint: Use `edgedb info` to find and check the config for this instance"); + return Err(err) + } else { + return Err(err) + } + } + }; Ok(Connection { - inner: raw::Connection::connect(&cfg).await?, + inner: connection, state: State::empty(), server_version: None, config: cfg.clone(), diff --git a/src/repl.rs b/src/repl.rs index 4f793db9e..51e82ed06 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -155,7 +155,7 @@ impl State { pub async fn try_connect(&mut self, database: &str) -> anyhow::Result<()> { let mut params = self.conn_params.clone(); params.database(database)?; - let mut conn = params.connect_interactive().await?; + let mut conn = params.connect().await?; let fetched_version = conn.get_version().await?; if self.last_version.as_ref() != Some(&fetched_version) { self.print_banner(&fetched_version)?; From aff1485d3f8dc0058800079b9586b304adf6ea63 Mon Sep 17 00:00:00 2001 From: Dhghomon <56599343+Dhghomon@users.noreply.github.com> Date: Fri, 3 Nov 2023 15:39:13 +0900 Subject: [PATCH 2/2] Add extra logging and timeout hints --- src/connect.rs | 7 ++++++- src/options.rs | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/connect.rs b/src/connect.rs index 632c83fd1..4e3c76ed7 100644 --- a/src/connect.rs +++ b/src/connect.rs @@ -172,7 +172,12 @@ impl Connector { _ => format!("EdgeDB instance at {}", cfg.display_addr()) }; - format!("Connecting to {}...", desc) + let wait = cfg.wait_until_available(); + let wait_msg = match wait.as_secs() { + seconds if seconds < 1 => format!("{}ms", wait.as_millis()), + seconds => format!("{seconds}s") + }; + format!("Connecting to {desc} (will try up to {wait_msg})...") } async fn print_warning(&self, cfg: &Config) diff --git a/src/options.rs b/src/options.rs index ef750b6a1..119f8a4f8 100644 --- a/src/options.rs +++ b/src/options.rs @@ -647,7 +647,10 @@ impl Options { } ); + let extra_help = "Hint: Setting RUST_LOG to `info`, `debug`, or `trace` can provide extra debugging info when encountering an issue.\n"; + let app = clap::Command::new("edgedb") + .after_help(extra_help) .term_width(term_width()) .args(deglobalized);