Skip to content
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

Scx1332/nicer error msg #174

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions crates/erc20_payment_lib_common/src/db/connection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::error::PaymentError;
use crate::error::*;
use crate::{err_custom_create, err_from};
use sqlx::migrate::Migrator;
use sqlx::migrate::{MigrateError, Migrator};
use sqlx::sqlite::SqliteConnectOptions;
use sqlx::SqlitePool;
use std::env;
Expand Down Expand Up @@ -54,7 +54,25 @@ pub async fn create_sqlite_connection(
.map_err(err_from!())?;

if run_migrations {
MIGRATOR.run(&pool).await.map_err(err_from!())?;
MIGRATOR.run(&pool).await.map_err(|e| {
let file_part = if let Some(path) = path {
format!("file {}", path.display())
} else {
url
};
match e {
MigrateError::VersionMissing(_) => {
err_custom_create!(
"Error during migration in {file_part}, probably previously run with newer version of application: {e}",
)
}
_ => {
err_custom_create!(
"Migration error in {file_part}: {e}",
)
}
}
})?
}

Ok(pool)
Expand Down
Loading