feat(crypto): Add a store error variant for breaking database format changes

This commit is contained in:
Damir Jelić
2022-03-22 14:48:00 +01:00
parent 0ce74b956c
commit 2bacbf1b53
2 changed files with 12 additions and 5 deletions

View File

@@ -597,6 +597,14 @@ pub enum CryptoStoreError {
/// The store failed to (de)serialize a data type.
#[error(transparent)]
Serialization(#[from] SerdeError),
/// The database format has changed in a backwards incompatible way.
#[error(
"The database format changed in an incompatible way, current \
version: {0}, latest version: {1}"
)]
UnsupportedDatabaseVersion(usize, usize),
/// A problem with the underlying database backend
#[error(transparent)]
Backend(#[from] anyhow::Error),

View File

@@ -486,11 +486,10 @@ impl SledStore {
}
if version <= 3 {
return Err(anyhow!(
"Unsupported database version, the database \
format changed in a backwards incompatible way"
)
.into());
return Err(CryptoStoreError::UnsupportedDatabaseVersion(
version.into(),
DATABASE_VERSION.into(),
));
}
self.inner