refactor(indexeddb): separate transaction and event cache error conversions

Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
This commit is contained in:
Michael Goldenberg
2025-07-09 12:38:01 -04:00
committed by Ivan Enderlin
parent 8d4e7f0478
commit a399840dff
2 changed files with 27 additions and 25 deletions

View File

@@ -59,27 +59,16 @@ impl From<web_sys::DomException> for IndexeddbEventCacheStoreError {
impl From<IndexeddbEventCacheStoreError> for EventCacheStoreError {
fn from(value: IndexeddbEventCacheStoreError) -> Self {
use IndexeddbEventCacheStoreError::*;
match value {
IndexeddbEventCacheStoreError::DomException { .. }
| IndexeddbEventCacheStoreError::ChunksContainCycle
| IndexeddbEventCacheStoreError::ChunksContainDisjointLists
| IndexeddbEventCacheStoreError::NoMaxChunkId
| IndexeddbEventCacheStoreError::UnableToLoadChunk => {
Self::InvalidData { details: value.to_string() }
}
IndexeddbEventCacheStoreError::Transaction(ref inner) => match inner {
IndexeddbEventCacheStoreTransactionError::DomException { .. } => {
Self::InvalidData { details: value.to_string() }
}
IndexeddbEventCacheStoreTransactionError::Serialization(e) => {
Self::Serialization(serde_json::Error::custom(e.to_string()))
}
IndexeddbEventCacheStoreTransactionError::ItemIsNotUnique
| IndexeddbEventCacheStoreTransactionError::ItemNotFound => {
Self::InvalidData { details: value.to_string() }
}
},
IndexeddbEventCacheStoreError::MemoryStore(inner) => inner,
DomException { .. }
| ChunksContainCycle
| ChunksContainDisjointLists
| NoMaxChunkId
| UnableToLoadChunk => Self::InvalidData { details: value.to_string() },
Transaction(inner) => inner.into(),
MemoryStore(inner) => inner,
}
}
}

View File

@@ -14,11 +14,14 @@
use indexed_db_futures::{prelude::IdbTransaction, IdbQuerySource};
use matrix_sdk_base::{
event_cache::{Event as RawEvent, Gap as RawGap},
event_cache::{store::EventCacheStoreError, Event as RawEvent, Gap as RawGap},
linked_chunk::{ChunkContent, ChunkIdentifier, RawChunk},
};
use ruma::{events::relation::RelationType, OwnedEventId, RoomId};
use serde::{de::DeserializeOwned, Serialize};
use serde::{
de::{DeserializeOwned, Error},
Serialize,
};
use thiserror::Error;
use web_sys::IdbCursorDirection;
@@ -55,9 +58,19 @@ impl From<web_sys::DomException> for IndexeddbEventCacheStoreTransactionError {
impl From<serde_wasm_bindgen::Error> for IndexeddbEventCacheStoreTransactionError {
fn from(e: serde_wasm_bindgen::Error) -> Self {
Self::Serialization(Box::new(<serde_json::Error as serde::de::Error>::custom(
e.to_string(),
)))
Self::Serialization(Box::new(serde_json::Error::custom(e.to_string())))
}
}
impl From<IndexeddbEventCacheStoreTransactionError> for EventCacheStoreError {
fn from(value: IndexeddbEventCacheStoreTransactionError) -> Self {
use IndexeddbEventCacheStoreTransactionError::*;
match value {
DomException { .. } => Self::InvalidData { details: value.to_string() },
Serialization(e) => Self::Serialization(serde_json::Error::custom(e.to_string())),
ItemIsNotUnique | ItemNotFound => Self::InvalidData { details: value.to_string() },
}
}
}