Remove deprecated `std::error::Error` methods
diff --git a/diesel/src/migration/errors.rs b/diesel/src/migration/errors.rs
index 3daeef4..262185d 100644
--- a/diesel/src/migration/errors.rs
+++ b/diesel/src/migration/errors.rs
@@ -27,31 +27,30 @@
__NonExhaustive,
}
-impl Error for MigrationError {
- fn description(&self) -> &str {
- match *self {
- MigrationError::MigrationDirectoryNotFound => {
- "Unable to find migrations directory in this directory or any parent directories."
- }
- MigrationError::UnknownMigrationFormat(_) => {
- "Invalid migration directory, the directory's name should be \
- <timestamp>_<name_of_migration>, and it should only contain up.sql and down.sql."
- }
- MigrationError::IoError(ref error) => error.description(),
- MigrationError::UnknownMigrationVersion(_) => {
- "Unable to find migration version to revert in the migrations directory."
- }
- MigrationError::NoMigrationRun => {
- "No migrations have been run. Did you forget `diesel migration run`?"
- }
- MigrationError::__NonExhaustive => unreachable!(),
- }
- }
-}
+impl Error for MigrationError {}
impl fmt::Display for MigrationError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
- self.description().fmt(f)
+ match *self {
+ MigrationError::MigrationDirectoryNotFound => write!(
+ f,
+ "Unable to find migrations directory in this directory or any parent directories."
+ ),
+ MigrationError::UnknownMigrationFormat(_) => {
+ write!(f,"Invalid migration directory, the directory's name should be \
+ <timestamp>_<name_of_migration>, and it should only contain up.sql and down.sql.")
+ }
+ MigrationError::IoError(ref error) => write!(f, "{}", error),
+ MigrationError::UnknownMigrationVersion(_) => write!(
+ f,
+ "Unable to find migration version to revert in the migrations directory."
+ ),
+ MigrationError::NoMigrationRun => write!(
+ f,
+ "No migrations have been run. Did you forget `diesel migration run`?"
+ ),
+ MigrationError::__NonExhaustive => unreachable!(),
+ }
}
}
@@ -92,20 +91,18 @@
__NonExhaustive,
}
-impl Error for RunMigrationsError {
- fn description(&self) -> &str {
- match *self {
- RunMigrationsError::MigrationError(ref error) => error.description(),
- RunMigrationsError::QueryError(ref error) => error.description(),
- RunMigrationsError::EmptyMigration => "Attempted to run an empty migration.",
- RunMigrationsError::__NonExhaustive => unreachable!(),
- }
- }
-}
+impl Error for RunMigrationsError {}
impl fmt::Display for RunMigrationsError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
- write!(f, "Failed with: {}", self.description())
+ match *self {
+ RunMigrationsError::MigrationError(ref error) => write!(f, "Failed with: {}", error),
+ RunMigrationsError::QueryError(ref error) => write!(f, "Failed with: {}", error),
+ RunMigrationsError::EmptyMigration => {
+ write!(f, "Failed with: Attempted to run an empty migration.")
+ }
+ RunMigrationsError::__NonExhaustive => unreachable!(),
+ }
}
}
diff --git a/diesel/src/result.rs b/diesel/src/result.rs
index fb89e1f..e8a0b49 100644
--- a/diesel/src/result.rs
+++ b/diesel/src/result.rs
@@ -267,36 +267,23 @@
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
- Error::InvalidCString(ref nul_err) => nul_err.fmt(f),
+ Error::InvalidCString(ref nul_err) => write!(f, "{}", nul_err),
Error::DatabaseError(_, ref e) => write!(f, "{}", e.message()),
- Error::NotFound => f.write_str("NotFound"),
+ Error::NotFound => f.write_str("Record not found"),
Error::QueryBuilderError(ref e) => e.fmt(f),
Error::DeserializationError(ref e) => e.fmt(f),
Error::SerializationError(ref e) => e.fmt(f),
- Error::RollbackTransaction => write!(f, "{}", self.description()),
- Error::AlreadyInTransaction => write!(f, "{}", self.description()),
+ Error::RollbackTransaction => write!(f, "The current transaction was aborted"),
+ Error::AlreadyInTransaction => write!(
+ f,
+ "Cannot perform this operation while a transaction is open",
+ ),
Error::__Nonexhaustive => unreachable!(),
}
}
}
impl StdError for Error {
- fn description(&self) -> &str {
- match *self {
- Error::InvalidCString(ref nul_err) => nul_err.description(),
- Error::DatabaseError(_, ref e) => e.message(),
- Error::NotFound => "Record not found",
- Error::QueryBuilderError(ref e) => e.description(),
- Error::DeserializationError(ref e) => e.description(),
- Error::SerializationError(ref e) => e.description(),
- Error::RollbackTransaction => "The current transaction was aborted",
- Error::AlreadyInTransaction => {
- "Cannot perform this operation while a transaction is open"
- }
- Error::__Nonexhaustive => unreachable!(),
- }
- }
-
fn cause(&self) -> Option<&dyn StdError> {
match *self {
Error::InvalidCString(ref e) => Some(e),
@@ -321,16 +308,6 @@
}
impl StdError for ConnectionError {
- fn description(&self) -> &str {
- match *self {
- ConnectionError::InvalidCString(ref nul_err) => nul_err.description(),
- ConnectionError::BadConnection(ref s) => s,
- ConnectionError::InvalidConnectionUrl(ref s) => s,
- ConnectionError::CouldntSetupConfiguration(ref e) => e.description(),
- ConnectionError::__Nonexhaustive => unreachable!(),
- }
- }
-
fn cause(&self) -> Option<&dyn StdError> {
match *self {
ConnectionError::InvalidCString(ref e) => Some(e),
@@ -372,12 +349,8 @@
impl fmt::Display for UnexpectedNullError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{}", self.description())
+ write!(f, "Unexpected null for non-null column")
}
}
-impl StdError for UnexpectedNullError {
- fn description(&self) -> &str {
- "Unexpected null for non-null column"
- }
-}
+impl StdError for UnexpectedNullError {}