From 6785c07793706b5fe2469f9948aee3da248eef15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Tue, 15 Mar 2022 14:18:48 +0100 Subject: [PATCH] indexeddb: Make store opening error more specific --- crates/matrix-sdk-indexeddb/src/lib.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/crates/matrix-sdk-indexeddb/src/lib.rs b/crates/matrix-sdk-indexeddb/src/lib.rs index c5e20bdd9..7b8ac9cef 100644 --- a/crates/matrix-sdk-indexeddb/src/lib.rs +++ b/crates/matrix-sdk-indexeddb/src/lib.rs @@ -1,5 +1,7 @@ #[cfg(target_arch = "wasm32")] -use matrix_sdk_base::store::StoreConfig; +use matrix_sdk_base::store::{StoreConfig, StoreError}; +#[cfg(target_arch = "wasm32")] +use thiserror::Error; mod safe_encode; @@ -14,6 +16,9 @@ mod cryptostore; #[cfg(feature = "encryption")] pub use cryptostore::IndexeddbStore as CryptoStore; #[cfg(target_arch = "wasm32")] +#[cfg(feature = "encryption")] +use cryptostore::IndexeddbStoreError; +#[cfg(target_arch = "wasm32")] pub use state_store::IndexeddbStore as StateStore; #[cfg(target_arch = "wasm32")] @@ -23,7 +28,7 @@ pub use state_store::IndexeddbStore as StateStore; async fn open_stores_with_name( name: impl Into, passphrase: Option<&str>, -) -> Result<(Box, Box), anyhow::Error> { +) -> Result<(Box, Box), OpenStoreError> { let name = name.into(); if let Some(passphrase) = passphrase { @@ -44,7 +49,7 @@ async fn open_stores_with_name( pub async fn make_store_config( name: impl Into, passphrase: Option<&str>, -) -> Result { +) -> Result { let name = name.into(); #[cfg(feature = "encryption")] @@ -64,3 +69,17 @@ pub async fn make_store_config( Ok(StoreConfig::new().state_store(Box::new(state_store))) } } + +#[cfg(target_arch = "wasm32")] +/// All the errors that can occur when opening an IndexedDB store. +#[derive(Error, Debug)] +pub enum OpenStoreError { + /// An error occurred with the state store implementation. + #[error(transparent)] + State(#[from] StoreError), + + /// An error occurred with the crypto store implementation. + #[cfg(feature = "encryption")] + #[error(transparent)] + Crypto(#[from] IndexeddbStoreError), +}