Skip to content

Commit bbe8f17

Browse files
committed
refactor(common): Rename LockStoreError to CrossProcessLockError.
This patch renames the `LockStoreError` enum to `CrossProcessLockError` to be consistent with the other types in the same module. The `BackingStoreError` variant is also renamed to `TryLockError`.
1 parent f65bb60 commit bbe8f17

File tree

8 files changed

+33
-28
lines changed

8 files changed

+33
-28
lines changed

crates/matrix-sdk-base/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
//! Error conditions.
1717
18-
use matrix_sdk_common::cross_process_lock::LockStoreError;
18+
use matrix_sdk_common::cross_process_lock::CrossProcessLockError;
1919
#[cfg(feature = "e2e-encryption")]
2020
use matrix_sdk_crypto::{CryptoStoreError, MegolmError, OlmError};
2121
use thiserror::Error;
@@ -51,7 +51,7 @@ pub enum Error {
5151

5252
/// An error happened while attempting to lock the event cache store.
5353
#[error(transparent)]
54-
EventCacheLock(#[from] LockStoreError),
54+
EventCacheLock(#[from] CrossProcessLockError),
5555

5656
/// An error occurred in the crypto store.
5757
#[cfg(feature = "e2e-encryption")]

crates/matrix-sdk-base/src/event_cache/store/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mod memory_store;
2828
mod traits;
2929

3030
use matrix_sdk_common::cross_process_lock::{
31-
CrossProcessLock, CrossProcessLockGuard, LockStoreError, TryLock,
31+
CrossProcessLock, CrossProcessLockError, CrossProcessLockGuard, TryLock,
3232
};
3333
pub use matrix_sdk_store_encryption::Error as StoreEncryptionError;
3434
use ruma::{
@@ -86,7 +86,7 @@ impl EventCacheStoreLock {
8686
}
8787

8888
/// Acquire a spin lock (see [`CrossProcessLock::spin_lock`]).
89-
pub async fn lock(&self) -> Result<EventCacheStoreLockGuard<'_>, LockStoreError> {
89+
pub async fn lock(&self) -> Result<EventCacheStoreLockGuard<'_>, CrossProcessLockError> {
9090
let cross_process_lock_guard = self.cross_process_lock.spin_lock(None).await?;
9191

9292
Ok(EventCacheStoreLockGuard { cross_process_lock_guard, store: self.store.deref() })

crates/matrix-sdk-base/src/media/store/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use std::fmt;
3232
use std::{ops::Deref, sync::Arc};
3333

3434
use matrix_sdk_common::cross_process_lock::{
35-
CrossProcessLock, CrossProcessLockGuard, LockStoreError, TryLock,
35+
CrossProcessLock, CrossProcessLockError, CrossProcessLockGuard, TryLock,
3636
};
3737
use matrix_sdk_store_encryption::Error as StoreEncryptionError;
3838
pub use traits::{DynMediaStore, IntoMediaStore, MediaStore, MediaStoreInner};
@@ -125,7 +125,7 @@ impl MediaStoreLock {
125125
}
126126

127127
/// Acquire a spin lock (see [`CrossProcessLock::spin_lock`]).
128-
pub async fn lock(&self) -> Result<MediaStoreLockGuard<'_>, LockStoreError> {
128+
pub async fn lock(&self) -> Result<MediaStoreLockGuard<'_>, CrossProcessLockError> {
129129
let cross_process_lock_guard = self.cross_process_lock.spin_lock(None).await?;
130130

131131
Ok(MediaStoreLockGuard { cross_process_lock_guard, store: self.store.deref() })

crates/matrix-sdk-common/src/cross_process_lock.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ where
190190

191191
/// Try to lock once, returns whether the lock was obtained or not.
192192
#[instrument(skip(self), fields(?self.lock_key, ?self.lock_holder))]
193-
pub async fn try_lock_once(&self) -> Result<Option<CrossProcessLockGuard>, LockStoreError> {
193+
pub async fn try_lock_once(
194+
&self,
195+
) -> Result<Option<CrossProcessLockGuard>, CrossProcessLockError> {
194196
// Hold onto the locking attempt mutex for the entire lifetime of this
195197
// function, to avoid multiple reentrant calls.
196198
let mut _attempt = self.locking_attempt.lock().await;
@@ -212,7 +214,7 @@ where
212214
.locker
213215
.try_lock(LEASE_DURATION_MS, &self.lock_key, &self.lock_holder)
214216
.await
215-
.map_err(|err| LockStoreError::BackingStoreError(Box::new(err)))?;
217+
.map_err(|err| CrossProcessLockError::TryLockError(Box::new(err)))?;
216218

217219
if !acquired {
218220
trace!("Couldn't acquire the lock immediately.");
@@ -302,7 +304,7 @@ where
302304
pub async fn spin_lock(
303305
&self,
304306
max_backoff: Option<u32>,
305-
) -> Result<CrossProcessLockGuard, LockStoreError> {
307+
) -> Result<CrossProcessLockGuard, CrossProcessLockError> {
306308
let max_backoff = max_backoff.unwrap_or(MAX_BACKOFF_MS);
307309

308310
// Note: reads/writes to the backoff are racy across threads in theory, but the
@@ -330,7 +332,7 @@ where
330332
}
331333
WaitingTime::Stop => {
332334
// We've reached the maximum backoff, abandon.
333-
return Err(LockStoreError::LockTimeout);
335+
return Err(CrossProcessLockError::LockTimeout);
334336
}
335337
};
336338

@@ -348,18 +350,18 @@ where
348350

349351
/// Error related to the locking API of the store.
350352
#[derive(Debug, thiserror::Error)]
351-
pub enum LockStoreError {
353+
pub enum CrossProcessLockError {
352354
/// Spent too long waiting for a database lock.
353355
#[error("a lock timed out")]
354356
LockTimeout,
355357

356358
#[error(transparent)]
357359
#[cfg(not(target_family = "wasm"))]
358-
BackingStoreError(#[from] Box<dyn Error + Send + Sync>),
360+
TryLockError(#[from] Box<dyn Error + Send + Sync>),
359361

360362
#[error(transparent)]
361363
#[cfg(target_family = "wasm")]
362-
BackingStoreError(Box<dyn Error>),
364+
TryLockError(Box<dyn Error>),
363365
}
364366

365367
#[cfg(test)]
@@ -379,8 +381,8 @@ mod tests {
379381
};
380382

381383
use super::{
382-
CrossProcessLock, CrossProcessLockGuard, EXTEND_LEASE_EVERY_MS, LockStoreError, TryLock,
383-
memory_store_helper::try_take_leased_lock,
384+
CrossProcessLock, CrossProcessLockError, CrossProcessLockGuard, EXTEND_LEASE_EVERY_MS,
385+
TryLock, memory_store_helper::try_take_leased_lock,
384386
};
385387

386388
#[derive(Clone, Default)]
@@ -416,7 +418,7 @@ mod tests {
416418
sleep(Duration::from_millis(EXTEND_LEASE_EVERY_MS)).await;
417419
}
418420

419-
type TestResult = Result<(), LockStoreError>;
421+
type TestResult = Result<(), CrossProcessLockError>;
420422

421423
#[async_test]
422424
async fn test_simple_lock_unlock() -> TestResult {
@@ -518,7 +520,7 @@ mod tests {
518520
.expect("lock was obtained after spin-locking");
519521

520522
// Now if lock1 tries to get the lock with a small timeout, it will fail.
521-
assert_matches!(lock1.spin_lock(Some(200)).await, Err(LockStoreError::LockTimeout));
523+
assert_matches!(lock1.spin_lock(Some(200)).await, Err(CrossProcessLockError::LockTimeout));
522524

523525
Ok(())
524526
}

crates/matrix-sdk/src/authentication/oauth/cross_process.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use matrix_sdk_base::crypto::{
55
store::{LockableCryptoStore, Store},
66
CryptoStoreError,
77
};
8-
use matrix_sdk_common::cross_process_lock::{CrossProcessLock, CrossProcessLockGuard, LockStoreError};
8+
use matrix_sdk_common::cross_process_lock::{
9+
CrossProcessLock, CrossProcessLockError, CrossProcessLockGuard,
10+
};
911
use sha2::{Digest as _, Sha256};
1012
use thiserror::Error;
1113
use tokio::sync::{Mutex, OwnedMutexGuard};
@@ -216,7 +218,7 @@ pub enum CrossProcessRefreshLockError {
216218

217219
/// The locking itself failed.
218220
#[error(transparent)]
219-
LockError(#[from] LockStoreError),
221+
LockError(#[from] CrossProcessLockError),
220222

221223
/// The previous hash isn't valid.
222224
#[error("the previous stored hash isn't a valid integer")]

crates/matrix-sdk/src/error.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ use thiserror::Error;
4646
use url::ParseError as UrlParseError;
4747

4848
use crate::{
49-
authentication::oauth::OAuthError, event_cache::EventCacheError, media::MediaError,
50-
room::reply::ReplyError, sliding_sync::Error as SlidingSyncError, cross_process_lock::LockStoreError,
49+
authentication::oauth::OAuthError, cross_process_lock::CrossProcessLockError,
50+
event_cache::EventCacheError, media::MediaError, room::reply::ReplyError,
51+
sliding_sync::Error as SlidingSyncError,
5152
};
5253

5354
/// Result type of the matrix-sdk.
@@ -315,7 +316,7 @@ pub enum Error {
315316

316317
/// An error occurred with a cross-process store lock.
317318
#[error(transparent)]
318-
CrossProcessLockError(Box<LockStoreError>),
319+
CrossProcessLockError(Box<CrossProcessLockError>),
319320

320321
/// An error occurred during a E2EE operation.
321322
#[cfg(feature = "e2e-encryption")]
@@ -479,8 +480,8 @@ impl From<CryptoStoreError> for Error {
479480
}
480481
}
481482

482-
impl From<LockStoreError> for Error {
483-
fn from(error: LockStoreError) -> Self {
483+
impl From<CrossProcessLockError> for Error {
484+
fn from(error: CrossProcessLockError) -> Self {
484485
Error::CrossProcessLockError(Box::new(error))
485486
}
486487
}

crates/matrix-sdk/src/event_cache/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use eyeball::{SharedObservable, Subscriber};
3737
use eyeball_im::VectorDiff;
3838
use futures_util::future::{join_all, try_join_all};
3939
use matrix_sdk_base::{
40+
cross_process_lock::CrossProcessLockError,
4041
deserialized_responses::{AmbiguityChange, TimelineEvent},
4142
event_cache::{
4243
store::{EventCacheStoreError, EventCacheStoreLock},
@@ -45,7 +46,6 @@ use matrix_sdk_base::{
4546
executor::AbortOnDrop,
4647
linked_chunk::{self, lazy_loader::LazyLoaderError, OwnedLinkedChunkId},
4748
serde_helpers::extract_thread_root_from_content,
48-
cross_process_lock::LockStoreError,
4949
sync::RoomUpdates,
5050
timer, ThreadingSupport,
5151
};
@@ -111,7 +111,7 @@ pub enum EventCacheError {
111111

112112
/// An error happening when attempting to (cross-process) lock storage.
113113
#[error(transparent)]
114-
LockingStorage(#[from] LockStoreError),
114+
LockingStorage(#[from] CrossProcessLockError),
115115

116116
/// The [`EventCache`] owns a weak reference to the [`Client`] it pertains
117117
/// to. It's possible this weak reference points to nothing anymore, at

crates/matrix-sdk/src/send_queue/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ use eyeball::SharedObservable;
141141
#[cfg(feature = "unstable-msc4274")]
142142
use matrix_sdk_base::store::FinishGalleryItemInfo;
143143
use matrix_sdk_base::{
144+
cross_process_lock::CrossProcessLockError,
144145
event_cache::store::EventCacheStoreError,
145146
media::{store::MediaStoreError, MediaRequestParameters},
146147
store::{
147148
ChildTransactionId, DependentQueuedRequest, DependentQueuedRequestKind, DynStateStore,
148149
FinishUploadThumbnailInfo, QueueWedgeError, QueuedRequest, QueuedRequestKind,
149150
SentMediaInfo, SentRequestKey, SerializableEventContent,
150151
},
151-
cross_process_lock::LockStoreError,
152152
RoomState, StoreError,
153153
};
154154
use matrix_sdk_common::{
@@ -2354,7 +2354,7 @@ pub enum RoomSendQueueStorageError {
23542354

23552355
/// Error caused when attempting to get a handle on the event cache store.
23562356
#[error(transparent)]
2357-
LockError(#[from] LockStoreError),
2357+
LockError(#[from] CrossProcessLockError),
23582358

23592359
/// Error caused when (de)serializing into/from json.
23602360
#[error(transparent)]

0 commit comments

Comments
 (0)