From 956294b20bd2519b352ef4d07eb057debc67938f Mon Sep 17 00:00:00 2001 From: sgrebnov Date: Thu, 1 Aug 2024 22:56:29 -0700 Subject: [PATCH 1/2] Improve MySQL auth error message --- src/sql/db_connection_pool/mysqlpool.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/sql/db_connection_pool/mysqlpool.rs b/src/sql/db_connection_pool/mysqlpool.rs index 3617e15..419dde1 100644 --- a/src/sql/db_connection_pool/mysqlpool.rs +++ b/src/sql/db_connection_pool/mysqlpool.rs @@ -3,7 +3,7 @@ use std::{collections::HashMap, path::PathBuf, sync::Arc}; use async_trait::async_trait; use mysql_async::{ prelude::{Queryable, ToValue}, - Params, Row, SslOpts, + DriverError, Params, Row, SslOpts, }; use secrecy::{ExposeSecret, Secret, SecretString}; use snafu::{ResultExt, Snafu}; @@ -125,7 +125,20 @@ impl MySQLConnectionPool { let pool = mysql_async::Pool::new(opts); // Test the connection - let mut conn = pool.get_conn().await.context(ConnectionPoolRunSnafu)?; + let mut conn = pool + .get_conn() + .await + .map_err(|err| match err { + // In case of an incorrect user name, the error `Unknown authentication plugin 'sha256_password'` is returned. + // We override it with a more user-friendly error message. + mysql_async::Error::Driver(DriverError::UnknownAuthPlugin { .. }) => { + mysql_async::Error::Other( + "Unable to authenticate. Are the user name and password correct?".into(), + ) + } + _ => err, + }) + .context(ConnectionPoolRunSnafu)?; let _rows: Vec = conn .exec("SELECT 1", Params::Empty) .await From 80d2817b0fc34a05b184ff97307d68c83783c2f3 Mon Sep 17 00:00:00 2001 From: Phillip LeBlanc Date: Fri, 2 Aug 2024 16:05:18 +0900 Subject: [PATCH 2/2] Update src/sql/db_connection_pool/mysqlpool.rs --- src/sql/db_connection_pool/mysqlpool.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sql/db_connection_pool/mysqlpool.rs b/src/sql/db_connection_pool/mysqlpool.rs index 419dde1..d485e51 100644 --- a/src/sql/db_connection_pool/mysqlpool.rs +++ b/src/sql/db_connection_pool/mysqlpool.rs @@ -133,7 +133,7 @@ impl MySQLConnectionPool { // We override it with a more user-friendly error message. mysql_async::Error::Driver(DriverError::UnknownAuthPlugin { .. }) => { mysql_async::Error::Other( - "Unable to authenticate. Are the user name and password correct?".into(), + "Unable to authenticate. Is the user name and password correct?".into(), ) } _ => err,