Skip to content

Commit

Permalink
zcash_client_sqlite: Use errors instead of panics for unimplemented o…
Browse files Browse the repository at this point in the history
…r unsupported down migrations.
  • Loading branch information
nuttycom committed Mar 7, 2024
1 parent 6079fe5 commit bdab673
Show file tree
Hide file tree
Showing 19 changed files with 24 additions and 29 deletions.
6 changes: 6 additions & 0 deletions zcash_client_sqlite/src/wallet/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,6 @@ impl RusqliteMigration for Migration {
}

fn down(&self, _transaction: &Transaction) -> Result<(), WalletMigrationError> {
panic!("Cannot revert this migration.");
Err(WalletMigrationError::CannotRevert(MIGRATION_ID))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

0 comments on commit bdab673

Please sign in to comment.