mirror of
https://github.com/mozilla-services/syncstorage-rs.git
synced 2026-05-05 12:16:21 +02:00
Rename MySQL error to use a more generic name (#1619)
* style: Rename MysqlError to SqlError as they are generic * refactor: Don't use legacy numerics contant and methods * style: Cargo fmt * style: Keep Mysql specific error in Mysql code --------- Co-authored-by: JR Conlin <jconlin+git@mozilla.com>
This commit is contained in:
parent
7f7cfb7897
commit
2ae1ef46df
@ -5,17 +5,17 @@ use http::StatusCode;
|
||||
use syncserver_common::{from_error, impl_fmt_display, ReportableError};
|
||||
use thiserror::Error;
|
||||
|
||||
/// Error specific to any MySQL database backend. These errors are not related to the syncstorage
|
||||
/// Error specific to any SQL database backend. These errors are not related to the syncstorage
|
||||
/// or tokenserver application logic; rather, they are lower-level errors arising from diesel.
|
||||
#[derive(Debug)]
|
||||
pub struct MysqlError {
|
||||
kind: MysqlErrorKind,
|
||||
pub struct SqlError {
|
||||
kind: SqlErrorKind,
|
||||
pub status: StatusCode,
|
||||
pub backtrace: Backtrace,
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
enum MysqlErrorKind {
|
||||
enum SqlErrorKind {
|
||||
#[error("A database error occurred: {}", _0)]
|
||||
DieselQuery(#[from] diesel::result::Error),
|
||||
|
||||
@ -29,8 +29,8 @@ enum MysqlErrorKind {
|
||||
Migration(diesel_migrations::RunMigrationsError),
|
||||
}
|
||||
|
||||
impl From<MysqlErrorKind> for MysqlError {
|
||||
fn from(kind: MysqlErrorKind) -> Self {
|
||||
impl From<SqlErrorKind> for SqlError {
|
||||
fn from(kind: SqlErrorKind) -> Self {
|
||||
Self {
|
||||
kind,
|
||||
status: StatusCode::INTERNAL_SERVER_ERROR,
|
||||
@ -39,11 +39,11 @@ impl From<MysqlErrorKind> for MysqlError {
|
||||
}
|
||||
}
|
||||
|
||||
impl ReportableError for MysqlError {
|
||||
impl ReportableError for SqlError {
|
||||
fn is_sentry_event(&self) -> bool {
|
||||
#[allow(clippy::match_like_matches_macro)]
|
||||
match &self.kind {
|
||||
MysqlErrorKind::Pool(_) => false,
|
||||
SqlErrorKind::Pool(_) => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
@ -51,10 +51,10 @@ impl ReportableError for MysqlError {
|
||||
fn metric_label(&self) -> Option<String> {
|
||||
Some(
|
||||
match self.kind {
|
||||
MysqlErrorKind::DieselQuery(_) => "storage.mysql.error.diesel_query",
|
||||
MysqlErrorKind::DieselConnection(_) => "storage.mysql.error.diesel_connection",
|
||||
MysqlErrorKind::Pool(_) => "storage.mysql.error.pool",
|
||||
MysqlErrorKind::Migration(_) => "storage.mysql.error.migration",
|
||||
SqlErrorKind::DieselQuery(_) => "storage.sql.error.diesel_query",
|
||||
SqlErrorKind::DieselConnection(_) => "storage.sql.error.diesel_connection",
|
||||
SqlErrorKind::Pool(_) => "storage.sql.error.pool",
|
||||
SqlErrorKind::Migration(_) => "storage.sql.error.migration",
|
||||
}
|
||||
.to_string(),
|
||||
)
|
||||
@ -65,21 +65,17 @@ impl ReportableError for MysqlError {
|
||||
}
|
||||
}
|
||||
|
||||
impl_fmt_display!(MysqlError, MysqlErrorKind);
|
||||
impl_fmt_display!(SqlError, SqlErrorKind);
|
||||
|
||||
from_error!(
|
||||
diesel::result::Error,
|
||||
MysqlError,
|
||||
MysqlErrorKind::DieselQuery
|
||||
);
|
||||
from_error!(diesel::result::Error, SqlError, SqlErrorKind::DieselQuery);
|
||||
from_error!(
|
||||
diesel::result::ConnectionError,
|
||||
MysqlError,
|
||||
MysqlErrorKind::DieselConnection
|
||||
SqlError,
|
||||
SqlErrorKind::DieselConnection
|
||||
);
|
||||
from_error!(diesel::r2d2::PoolError, MysqlError, MysqlErrorKind::Pool);
|
||||
from_error!(diesel::r2d2::PoolError, SqlError, SqlErrorKind::Pool);
|
||||
from_error!(
|
||||
diesel_migrations::RunMigrationsError,
|
||||
MysqlError,
|
||||
MysqlErrorKind::Migration
|
||||
SqlError,
|
||||
SqlErrorKind::Migration
|
||||
);
|
||||
|
||||
@ -3,7 +3,7 @@ use std::fmt;
|
||||
use backtrace::Backtrace;
|
||||
use http::StatusCode;
|
||||
use syncserver_common::{from_error, impl_fmt_display, InternalError, ReportableError};
|
||||
use syncserver_db_common::error::MysqlError;
|
||||
use syncserver_db_common::error::SqlError;
|
||||
use syncstorage_db_common::error::{DbErrorIntrospect, SyncstorageDbError};
|
||||
use thiserror::Error;
|
||||
|
||||
@ -49,7 +49,7 @@ enum DbErrorKind {
|
||||
Common(SyncstorageDbError),
|
||||
|
||||
#[error("{}", _0)]
|
||||
Mysql(MysqlError),
|
||||
Mysql(SqlError),
|
||||
}
|
||||
|
||||
impl From<DbErrorKind> for DbError {
|
||||
@ -140,24 +140,24 @@ from_error!(SyncstorageDbError, DbError, DbErrorKind::Common);
|
||||
from_error!(
|
||||
diesel::result::Error,
|
||||
DbError,
|
||||
|error: diesel::result::Error| DbError::from(DbErrorKind::Mysql(MysqlError::from(error)))
|
||||
|error: diesel::result::Error| DbError::from(DbErrorKind::Mysql(SqlError::from(error)))
|
||||
);
|
||||
from_error!(
|
||||
diesel::result::ConnectionError,
|
||||
DbError,
|
||||
|error: diesel::result::ConnectionError| DbError::from(DbErrorKind::Mysql(MysqlError::from(
|
||||
|error: diesel::result::ConnectionError| DbError::from(DbErrorKind::Mysql(SqlError::from(
|
||||
error
|
||||
)))
|
||||
);
|
||||
from_error!(
|
||||
diesel::r2d2::PoolError,
|
||||
DbError,
|
||||
|error: diesel::r2d2::PoolError| DbError::from(DbErrorKind::Mysql(MysqlError::from(error)))
|
||||
|error: diesel::r2d2::PoolError| DbError::from(DbErrorKind::Mysql(SqlError::from(error)))
|
||||
);
|
||||
from_error!(
|
||||
diesel_migrations::RunMigrationsError,
|
||||
DbError,
|
||||
|error: diesel_migrations::RunMigrationsError| DbError::from(DbErrorKind::Mysql(
|
||||
MysqlError::from(error)
|
||||
SqlError::from(error)
|
||||
))
|
||||
);
|
||||
|
||||
@ -3,7 +3,7 @@ use std::fmt;
|
||||
use backtrace::Backtrace;
|
||||
use http::StatusCode;
|
||||
use syncserver_common::{from_error, impl_fmt_display, InternalError, ReportableError};
|
||||
use syncserver_db_common::error::MysqlError;
|
||||
use syncserver_db_common::error::SqlError;
|
||||
use thiserror::Error;
|
||||
use tokenserver_common::TokenserverError;
|
||||
|
||||
@ -28,21 +28,21 @@ impl DbError {
|
||||
impl ReportableError for DbError {
|
||||
fn backtrace(&self) -> Option<&Backtrace> {
|
||||
match &self.kind {
|
||||
DbErrorKind::Mysql(e) => e.backtrace(),
|
||||
DbErrorKind::Sql(e) => e.backtrace(),
|
||||
_ => Some(&self.backtrace),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_sentry_event(&self) -> bool {
|
||||
match &self.kind {
|
||||
DbErrorKind::Mysql(e) => e.is_sentry_event(),
|
||||
DbErrorKind::Sql(e) => e.is_sentry_event(),
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn metric_label(&self) -> Option<String> {
|
||||
match &self.kind {
|
||||
DbErrorKind::Mysql(e) => e.metric_label(),
|
||||
DbErrorKind::Sql(e) => e.metric_label(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -51,7 +51,7 @@ impl ReportableError for DbError {
|
||||
#[derive(Debug, Error)]
|
||||
enum DbErrorKind {
|
||||
#[error("{}", _0)]
|
||||
Mysql(MysqlError),
|
||||
Sql(SqlError),
|
||||
|
||||
#[error("Unexpected error: {}", _0)]
|
||||
Internal(String),
|
||||
@ -60,7 +60,7 @@ enum DbErrorKind {
|
||||
impl From<DbErrorKind> for DbError {
|
||||
fn from(kind: DbErrorKind) -> Self {
|
||||
match kind {
|
||||
DbErrorKind::Mysql(ref mysql_error) => Self {
|
||||
DbErrorKind::Sql(ref mysql_error) => Self {
|
||||
status: mysql_error.status,
|
||||
backtrace: Box::new(mysql_error.backtrace.clone()),
|
||||
kind,
|
||||
@ -105,24 +105,22 @@ impl_fmt_display!(DbError, DbErrorKind);
|
||||
from_error!(
|
||||
diesel::result::Error,
|
||||
DbError,
|
||||
|error: diesel::result::Error| DbError::from(DbErrorKind::Mysql(MysqlError::from(error)))
|
||||
|error: diesel::result::Error| DbError::from(DbErrorKind::Sql(SqlError::from(error)))
|
||||
);
|
||||
from_error!(
|
||||
diesel::result::ConnectionError,
|
||||
DbError,
|
||||
|error: diesel::result::ConnectionError| DbError::from(DbErrorKind::Mysql(MysqlError::from(
|
||||
error
|
||||
)))
|
||||
|error: diesel::result::ConnectionError| DbError::from(DbErrorKind::Sql(SqlError::from(error)))
|
||||
);
|
||||
from_error!(
|
||||
diesel::r2d2::PoolError,
|
||||
DbError,
|
||||
|error: diesel::r2d2::PoolError| DbError::from(DbErrorKind::Mysql(MysqlError::from(error)))
|
||||
|error: diesel::r2d2::PoolError| DbError::from(DbErrorKind::Sql(SqlError::from(error)))
|
||||
);
|
||||
from_error!(
|
||||
diesel_migrations::RunMigrationsError,
|
||||
DbError,
|
||||
|error: diesel_migrations::RunMigrationsError| DbError::from(DbErrorKind::Mysql(
|
||||
MysqlError::from(error)
|
||||
))
|
||||
|error: diesel_migrations::RunMigrationsError| DbError::from(DbErrorKind::Sql(SqlError::from(
|
||||
error
|
||||
)))
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user