Skip to content

Commit d567a45

Browse files
mgoldenbergHywan
authored andcommitted
feat(indexeddb): add error type for communicating errors outside of module
Signed-off-by: Michael Goldenberg <[email protected]>
1 parent 9c08cd8 commit d567a45

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

crates/matrix-sdk-indexeddb/src/event_cache_store/builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use web_sys::DomException;
2020

2121
use crate::{
2222
event_cache_store::{
23-
migrations::open_and_upgrade_db, serializer::IndexeddbEventCacheStoreSerializer,
24-
IndexeddbEventCacheStore,
23+
error::IndexeddbEventCacheStoreError, migrations::open_and_upgrade_db,
24+
serializer::IndexeddbEventCacheStoreSerializer, IndexeddbEventCacheStore,
2525
},
2626
serializer::IndexeddbSerializer,
2727
};
@@ -64,7 +64,7 @@ impl IndexeddbEventCacheStoreBuilder {
6464
/// Opens the IndexedDB database with the provided name. If successfully
6565
/// opened, builds the [`IndexeddbEventCacheStore`] with that database
6666
/// and the provided store cipher.
67-
pub async fn build(self) -> Result<IndexeddbEventCacheStore, DomException> {
67+
pub async fn build(self) -> Result<IndexeddbEventCacheStore, IndexeddbEventCacheStoreError> {
6868
Ok(IndexeddbEventCacheStore {
6969
inner: open_and_upgrade_db(&self.database_name).await?,
7070
serializer: IndexeddbEventCacheStoreSerializer::new(IndexeddbSerializer::new(

crates/matrix-sdk-indexeddb/src/event_cache_store/error.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License
1414

1515
use matrix_sdk_base::{SendOutsideWasm, SyncOutsideWasm};
16+
use thiserror::Error;
1617

1718
/// A trait that combines the necessary traits needed for asynchronous runtimes,
1819
/// but excludes them when running in a web environment - i.e., when
@@ -21,3 +22,19 @@ pub trait AsyncErrorDeps: std::error::Error + SendOutsideWasm + SyncOutsideWasm
2122

2223
impl<T> AsyncErrorDeps for T where T: std::error::Error + SendOutsideWasm + SyncOutsideWasm + 'static
2324
{}
25+
26+
#[derive(Debug, Error)]
27+
pub enum IndexeddbEventCacheStoreError {
28+
#[error("DomException {name} ({code}): {message}")]
29+
DomException { name: String, message: String, code: u16 },
30+
}
31+
32+
impl From<web_sys::DomException> for IndexeddbEventCacheStoreError {
33+
fn from(value: web_sys::DomException) -> IndexeddbEventCacheStoreError {
34+
IndexeddbEventCacheStoreError::DomException {
35+
name: value.name(),
36+
message: value.message(),
37+
code: value.code(),
38+
}
39+
}
40+
}

crates/matrix-sdk-indexeddb/src/event_cache_store/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ mod transaction;
2828
mod types;
2929

3030
pub use builder::IndexeddbEventCacheStoreBuilder;
31+
pub use error::IndexeddbEventCacheStoreError;
3132

3233
/// A type for providing an IndexedDB implementation of [`EventCacheStore`][1].
3334
/// This is meant to be used as a backend to [`EventCacheStore`][1] in browser

0 commit comments

Comments
 (0)