zcash_client_sqlite: Use errors instead of panics for unimplemented or unsupported down migrations.

This commit is contained in:
Kris Nuttycombe 2024-03-06 10:07:08 -07:00 committed by Jack Grigg
parent 54addb6ca6
commit c107f3df11
20 changed files with 28 additions and 29 deletions

View File

@ -31,8 +31,10 @@ and this library adheres to Rust's notion of
- Added `UnknownZip32Derivation`
- Added `BadAccountData`
- Removed `DiversifierIndexOutOfRange`
- `zcash_client_sqlite::wallet::init::WalletMigrationError` has added variant
`AddressGeneration`
- `zcash_client_sqlite::wallet`:
- `init::WalletMigrationError` has added variants:
- `WalletMigrationError::AddressGeneration`
- `WalletMigrationError::CannotRevert`
## [0.9.0] - 2024-03-01

View File

@ -36,6 +36,9 @@ pub enum WalletMigrationError {
/// Wrapper for commitment tree invariant violations
CommitmentTree(ShardTreeError<commitment_tree::Error>),
/// Reverting the specified migration is not supported.
CannotRevert(Uuid),
}
impl From<rusqlite::Error> for WalletMigrationError {
@ -80,6 +83,9 @@ impl fmt::Display for WalletMigrationError {
WalletMigrationError::AddressGeneration(e) => {
write!(f, "Address generation error: {:?}", e)
}
WalletMigrationError::CannotRevert(uuid) => {
write!(f, "Reverting migration {} is not supported", uuid)
}
}
}
}

View File

@ -69,6 +69,6 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
}
fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), Self::Error> {
panic!("This migration cannot be reverted.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -266,8 +266,7 @@ impl RusqliteMigration for Migration {
}
fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> {
// TODO: something better than just panic?
panic!("Cannot revert this migration.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -125,8 +125,7 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
}
fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> {
// TODO: something better than just panic?
panic!("Cannot revert this migration.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -174,8 +174,7 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
}
fn down(&self, _transaction: &Transaction) -> Result<(), WalletMigrationError> {
// TODO: something better than just panic?
panic!("Cannot revert this migration.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -427,6 +427,6 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
}
fn down(&self, _transaction: &Transaction) -> Result<(), WalletMigrationError> {
panic!("Cannot revert this migration.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -104,6 +104,6 @@ impl RusqliteMigration for Migration {
fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> {
// We should never down-migrate the first migration, as that can irreversibly
// destroy data.
panic!("Cannot revert the initial migration.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -217,8 +217,7 @@ impl RusqliteMigration for Migration {
}
fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> {
// TODO: something better than just panic?
panic!("Cannot revert this migration.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -271,8 +271,7 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
}
fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> {
// TODO: something better than just panic?
panic!("Cannot revert this migration.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -212,6 +212,6 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
}
fn down(&self, _: &rusqlite::Transaction) -> Result<(), Self::Error> {
panic!("Reversing this migration is not supported.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -74,7 +74,6 @@ impl RusqliteMigration for Migration {
}
fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> {
// TODO: something better than just panic?
panic!("Cannot revert this migration.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -277,7 +277,6 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
}
fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> {
// TODO: something better than just panic?
panic!("Cannot revert this migration.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -260,7 +260,6 @@ impl<P: consensus::Parameters> RusqliteMigration for Migration<P> {
}
fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> {
// TODO: something better than just panic?
panic!("Cannot revert this migration.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -196,8 +196,7 @@ impl RusqliteMigration for Migration {
}
fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), WalletMigrationError> {
// TODO: something better than just panic?
panic!("Cannot revert this migration.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -154,7 +154,7 @@ impl RusqliteMigration for Migration {
}
fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), Self::Error> {
panic!("This migration cannot be reverted.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -150,6 +150,6 @@ impl RusqliteMigration for Migration {
}
fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), Self::Error> {
panic!("This migration cannot be reverted.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -186,6 +186,6 @@ impl RusqliteMigration for Migration {
}
fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), Self::Error> {
panic!("This migration cannot be reverted.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -87,6 +87,6 @@ impl RusqliteMigration for Migration {
}
fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), Self::Error> {
panic!("This migration cannot be reverted.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}

View File

@ -84,6 +84,6 @@ impl RusqliteMigration for Migration {
}
fn down(&self, _transaction: &rusqlite::Transaction) -> Result<(), Self::Error> {
panic!("This migration cannot be reverted.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}