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

Improve MySQL auth error message #29

Merged
Merged
Changes from 2 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
17 changes: 15 additions & 2 deletions src/sql/db_connection_pool/mysqlpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(),
phillipleblanc marked this conversation as resolved.
Show resolved Hide resolved
)
}
_ => err,
})
.context(ConnectionPoolRunSnafu)?;
let _rows: Vec<Row> = conn
.exec("SELECT 1", Params::Empty)
.await
Expand Down