Skip to content

Commit

Permalink
fix: improve errors when hitting an idb error during IndexedDB migration
Browse files Browse the repository at this point in the history
The old error swallowed the underlying idb error.
  • Loading branch information
SimonThormeyer committed Nov 27, 2024
1 parent 3896bab commit 8512391
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion keystore/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ pub enum CryptoKeystoreError {
IdbError(#[from] idb::Error),
#[cfg(target_family = "wasm")]
#[error(transparent)]
CryptoKeystoreErrorV1_0_0(#[from] keystore_v_1_0_0::CryptoKeystoreError),
CryptoKeystoreErrorV1_0_0(keystore_v_1_0_0::CryptoKeystoreError),
#[cfg(target_family = "wasm")]
#[error(transparent)]
IdbErrorCryptoKeystoreV1_0_0(idb::Error),
#[cfg(target_family = "wasm")]
#[error(transparent)]
RexieErrorCryptoKeystoreV1_0_0(rexie::Error),
#[cfg(target_family = "wasm")]
#[error("Migration from version {0} is not supported")]
MigrationNotSupported(u32),
Expand All @@ -169,6 +175,19 @@ pub enum CryptoKeystoreError {
MigrationFailed,
}

#[cfg(target_family = "wasm")]
impl From<keystore_v_1_0_0::CryptoKeystoreError> for CryptoKeystoreError {
fn from(e: keystore_v_1_0_0::CryptoKeystoreError) -> Self {
match e {
keystore_v_1_0_0::CryptoKeystoreError::RexieError(rexie_error) => match rexie_error {
rexie::Error::IdbError(idb_error) => Self::IdbErrorCryptoKeystoreV1_0_0(idb_error),
_ => Self::RexieErrorCryptoKeystoreV1_0_0(rexie_error),
},
_ => Self::CryptoKeystoreErrorV1_0_0(e),
}
}
}

#[cfg(target_family = "wasm")]
impl From<wasm_bindgen::JsValue> for CryptoKeystoreError {
fn from(jsv: wasm_bindgen::JsValue) -> Self {
Expand Down

0 comments on commit 8512391

Please sign in to comment.