Merge pull request #1240 from zcash/migration-errors
zcash_client_sqlite: Use errors instead of panics in down-migrations
This commit is contained in:
commit
aeb51708ca
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue