Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hint when authentication fails, rv interactive #1169

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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};
Expand Down Expand Up @@ -151,18 +151,14 @@
self
}
pub async fn connect(&self) -> Result<Connection, anyhow::Error> {
self._connect(false).await
self._connect().await
}

pub async fn connect_interactive(&self) -> Result<Connection, anyhow::Error> {
self._connect(true).await
}

async fn _connect(&self, interactive: bool) -> Result<Connection, anyhow::Error> {
async fn _connect(&self) -> Result<Connection, anyhow::Error> {
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)
}
Expand All @@ -176,19 +172,20 @@
_ =>
format!("EdgeDB instance at {}", cfg.display_addr())
};
format!("Connecting to {}...", desc)
let wait = cfg.wait_until_available();

Check failure on line 175 in src/connect.rs

View workflow job for this annotation

GitHub Actions / portable-tests-macos (portable_project_dir)

no method named `wait_until_available` found for reference `&edgedb_tokio::Config` in the current scope

Check failure on line 175 in src/connect.rs

View workflow job for this annotation

GitHub Actions / portable-install-tests (ubuntu-20.04)

no method named `wait_until_available` found for reference `&edgedb_tokio::Config` in the current scope

Check failure on line 175 in src/connect.rs

View workflow job for this annotation

GitHub Actions / portable-tests-macos (portable_project)

no method named `wait_until_available` found for reference `&edgedb_tokio::Config` in the current scope

Check failure on line 175 in src/connect.rs

View workflow job for this annotation

GitHub Actions / musl-test (ubuntu-latest, nightly)

no method named `wait_until_available` found for reference `&edgedb_tokio::Config` in the current scope

Check failure on line 175 in src/connect.rs

View workflow job for this annotation

GitHub Actions / portable-tests-macos (portable_shared)

no method named `wait_until_available` found for reference `&edgedb_tokio::Config` in the current scope

Check failure on line 175 in src/connect.rs

View workflow job for this annotation

GitHub Actions / portable-tests-macos (portable_smoke)

no method named `wait_until_available` found for reference `&edgedb_tokio::Config` in the current scope

Check failure on line 175 in src/connect.rs

View workflow job for this annotation

GitHub Actions / test-bin-installable (ubuntu-latest)

no method named `wait_until_available` found for reference `&edgedb_tokio::Config` in the current scope

Check failure on line 175 in src/connect.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, nightly)

no method named `wait_until_available` found for reference `&edgedb_tokio::Config` in the current scope
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, interactive: bool)
async fn print_warning(&self, cfg: &Config)
-> Result<Connection, Error>
{
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> {
Expand All @@ -198,8 +195,20 @@

impl Connection {
pub async fn connect(cfg: &Config) -> Result<Connection, Error> {
let connection = match raw::Connection::connect(&cfg).await {
Ok(conn) => conn,
Err(err) => {
if err.is::<AuthenticationError>() {
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(),
Expand Down
3 changes: 3 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
Loading