Skip to content

Commit a399840

Browse files
mgoldenbergHywan
authored andcommitted
refactor(indexeddb): separate transaction and event cache error conversions
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
1 parent 8d4e7f0 commit a399840

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

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

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,16 @@ impl From<web_sys::DomException> for IndexeddbEventCacheStoreError {
5959

6060
impl From<IndexeddbEventCacheStoreError> for EventCacheStoreError {
6161
fn from(value: IndexeddbEventCacheStoreError) -> Self {
62+
use IndexeddbEventCacheStoreError::*;
63+
6264
match value {
63-
IndexeddbEventCacheStoreError::DomException { .. }
64-
| IndexeddbEventCacheStoreError::ChunksContainCycle
65-
| IndexeddbEventCacheStoreError::ChunksContainDisjointLists
66-
| IndexeddbEventCacheStoreError::NoMaxChunkId
67-
| IndexeddbEventCacheStoreError::UnableToLoadChunk => {
68-
Self::InvalidData { details: value.to_string() }
69-
}
70-
IndexeddbEventCacheStoreError::Transaction(ref inner) => match inner {
71-
IndexeddbEventCacheStoreTransactionError::DomException { .. } => {
72-
Self::InvalidData { details: value.to_string() }
73-
}
74-
IndexeddbEventCacheStoreTransactionError::Serialization(e) => {
75-
Self::Serialization(serde_json::Error::custom(e.to_string()))
76-
}
77-
IndexeddbEventCacheStoreTransactionError::ItemIsNotUnique
78-
| IndexeddbEventCacheStoreTransactionError::ItemNotFound => {
79-
Self::InvalidData { details: value.to_string() }
80-
}
81-
},
82-
IndexeddbEventCacheStoreError::MemoryStore(inner) => inner,
65+
DomException { .. }
66+
| ChunksContainCycle
67+
| ChunksContainDisjointLists
68+
| NoMaxChunkId
69+
| UnableToLoadChunk => Self::InvalidData { details: value.to_string() },
70+
Transaction(inner) => inner.into(),
71+
MemoryStore(inner) => inner,
8372
}
8473
}
8574
}

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414

1515
use indexed_db_futures::{prelude::IdbTransaction, IdbQuerySource};
1616
use matrix_sdk_base::{
17-
event_cache::{Event as RawEvent, Gap as RawGap},
17+
event_cache::{store::EventCacheStoreError, Event as RawEvent, Gap as RawGap},
1818
linked_chunk::{ChunkContent, ChunkIdentifier, RawChunk},
1919
};
2020
use ruma::{events::relation::RelationType, OwnedEventId, RoomId};
21-
use serde::{de::DeserializeOwned, Serialize};
21+
use serde::{
22+
de::{DeserializeOwned, Error},
23+
Serialize,
24+
};
2225
use thiserror::Error;
2326
use web_sys::IdbCursorDirection;
2427

@@ -55,9 +58,19 @@ impl From<web_sys::DomException> for IndexeddbEventCacheStoreTransactionError {
5558

5659
impl From<serde_wasm_bindgen::Error> for IndexeddbEventCacheStoreTransactionError {
5760
fn from(e: serde_wasm_bindgen::Error) -> Self {
58-
Self::Serialization(Box::new(<serde_json::Error as serde::de::Error>::custom(
59-
e.to_string(),
60-
)))
61+
Self::Serialization(Box::new(serde_json::Error::custom(e.to_string())))
62+
}
63+
}
64+
65+
impl From<IndexeddbEventCacheStoreTransactionError> for EventCacheStoreError {
66+
fn from(value: IndexeddbEventCacheStoreTransactionError) -> Self {
67+
use IndexeddbEventCacheStoreTransactionError::*;
68+
69+
match value {
70+
DomException { .. } => Self::InvalidData { details: value.to_string() },
71+
Serialization(e) => Self::Serialization(serde_json::Error::custom(e.to_string())),
72+
ItemIsNotUnique | ItemNotFound => Self::InvalidData { details: value.to_string() },
73+
}
6174
}
6275
}
6376

0 commit comments

Comments
 (0)