Better migration error message

This commit is contained in:
Antoine Gersant 2024-07-13 18:28:51 -07:00
parent 0e63f64513
commit 1020f27413
2 changed files with 4 additions and 4 deletions

View file

@ -17,8 +17,8 @@ pub enum Error {
ConnectionPool, ConnectionPool,
#[error("Filesystem error for `{0}`: `{1}`")] #[error("Filesystem error for `{0}`: `{1}`")]
Io(PathBuf, std::io::Error), Io(PathBuf, std::io::Error),
#[error("Could not apply database migrations")] #[error("Could not apply database migrations: {0}")]
Migration, Migration(sqlx::migrate::MigrateError),
} }
#[derive(Clone)] #[derive(Clone)]
@ -53,7 +53,7 @@ impl DB {
.run(&self.pool) .run(&self.pool)
.await .await
.and(Ok(())) .and(Ok(()))
.or(Err(Error::Migration)) .map_err(Error::Migration)
} }
} }

View file

@ -173,7 +173,7 @@ impl From<db::Error> for APIError {
db::Error::ConnectionPoolBuild => APIError::Internal, db::Error::ConnectionPoolBuild => APIError::Internal,
db::Error::ConnectionPool => APIError::Internal, db::Error::ConnectionPool => APIError::Internal,
db::Error::Io(p, e) => APIError::Io(p, e), db::Error::Io(p, e) => APIError::Io(p, e),
db::Error::Migration => APIError::Internal, db::Error::Migration(_) => APIError::Internal,
} }
} }
} }