t_rust_less_lib/block_store/
error.rs1use serde::{Deserialize, Serialize};
2use std::convert::From;
3use thiserror::Error;
4use zeroize::Zeroize;
5
6#[derive(Debug, Error, PartialEq, Eq, Serialize, Deserialize, Zeroize, Clone)]
7#[cfg_attr(feature = "with_specta", derive(specta::Type))]
8#[zeroize(drop)]
9pub enum StoreError {
10 #[error("Invalid block: {0}")]
11 InvalidBlock(String),
12 #[error("Invalid store url: {0}")]
13 InvalidStoreUrl(String),
14 #[error("IO: {0}")]
15 IO(String),
16 #[error("Mutex: {0}")]
17 Mutex(String),
18 #[error("Conflict: {0}")]
19 Conflict(String),
20 #[error("Store with name {0} not found")]
21 StoreNotFound(String),
22}
23
24pub type StoreResult<T> = Result<T, StoreError>;
25
26error_convert_from!(std::io::Error, StoreError, IO(display));
27error_convert_from!(url::ParseError, StoreError, InvalidStoreUrl(display));
28#[cfg(feature = "sled")]
29error_convert_from!(sled::Error, StoreError, IO(display));
30#[cfg(feature = "sled")]
31error_convert_from!(rmp_serde::encode::Error, StoreError, IO(display));
32#[cfg(feature = "sled")]
33error_convert_from!(rmp_serde::decode::Error, StoreError, IO(display));
34#[cfg(feature = "dropbox")]
35error_convert_from!(std::sync::mpsc::RecvError, StoreError, IO(display));
36#[cfg(feature = "dropbox")]
37error_convert_from!(dropbox_sdk::files::ListFolderError, StoreError, IO(display));
38#[cfg(feature = "dropbox")]
39error_convert_from!(dropbox_sdk::files::ListFolderContinueError, StoreError, IO(display));
40#[cfg(feature = "dropbox")]
41error_convert_from!(dropbox_sdk::files::UploadError, StoreError, IO(display));
42#[cfg(feature = "dropbox")]
43impl<E: std::error::Error> From<dropbox_sdk::Error<E>> for StoreError {
44 fn from(error: dropbox_sdk::Error<E>) -> Self {
45 StoreError::Mutex(format!("{error}"))
46 }
47}
48
49impl<T> From<std::sync::PoisonError<T>> for StoreError {
50 fn from(error: std::sync::PoisonError<T>) -> Self {
51 StoreError::Mutex(format!("{error}"))
52 }
53}
54
55#[cfg(feature = "sled")]
56impl From<sled::transaction::TransactionError<StoreError>> for StoreError {
57 fn from(err: sled::transaction::TransactionError<StoreError>) -> Self {
58 match err {
59 sled::transaction::TransactionError::Abort(err) => err,
60 sled::transaction::TransactionError::Storage(err) => err.into(),
61 }
62 }
63}