-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
enhancementNew feature or requestNew feature or request
Description
I have found these related issues/pull requests
The only somewhat related issue I was able to find is this one: #658
Description
Matching sqlx errors and database errors currently requires either writing match statements with complicated and lengthy clauses, or nested match statements, which are both unergonomic.
This proposal attempts to address this by adding a new method to the 'DatabaseError' trait which allows matching the ErrorKind and constraint name in one go. This would make error matching code simpler and more readable.
Prefered solution
Here is an example implementation
pub trait DatabaseError: 'static + Send + Sync + StdError {
fn matches(&self, kind: ErrorKind, constraint_name: &str) -> bool {
self.kind() == kind && self.constraint_name() == Some(constraint_name)
}
}Example use:
if (dbe.matches(ErrorKind::ForeignKeyViolation, "user_id")) {
// do something here....
}Is this a breaking change? Why or why not?
This would not modify any existing methods of the DatabaseError trait, it would therefore not be a breaking change.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request