-
Notifications
You must be signed in to change notification settings - Fork 51
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
Rename MySQL error to use a more generic name #1619
Merged
jrconlin
merged 5 commits into
mozilla-services:master
from
Eragonfr:rename-mysql-generic
Dec 4, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f646ddf
style: Rename MysqlError to SqlError as they are generic
Eragonfr f423a33
refactor: Don't use legacy numerics contant and methods
Eragonfr af22b24
style: Cargo fmt
Eragonfr 07a816a
style: Keep Mysql specific error in Mysql code
Eragonfr ac431de
Merge branch 'master' into rename-mysql-generic
jrconlin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,22 +39,22 @@ 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, | ||
} | ||
} | ||
|
||
fn metric_label(&self) -> Option<String> { | ||
Some( | ||
match self.kind { | ||
MysqlErrorKind::DieselQuery(_) => "storage.mysql.error.diesel_query", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These metric changes do not impact our dashboards. |
||
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 | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment still stands, "lower-level errors arising from diesel" and I think suggests a clearer name for this:
DieselError
, how does that sound?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like a good name too. As all errors are from diesel or it's dependencies (r2d2 or diesel_migrations).
But if we use
SqlError
that means that we could replace diesel with an other ORM.If someone wants to support a database that's not supported by Diesel. But maybe in that case they'll need to do something similar to the spanner backend.
Idk. If @jrconlin and @taddes prefer
DieselError
I can change it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I'm fine either way, but I do appreciate the concept of having a more generic
SqlError
for the reason that @Eragonfr notes. I don't really see us replacing diesel any time soon, but the sources of the error being reported are coming from the underlying SQL system.DieselError
type should be reserved for errors arising from the diesel system directly (e.g. failure to connect to the data store, or some configuration break).