Skip to content

Commit 7de3d3e

Browse files
authored
Merge pull request #7517 from drmingdrmer/5-err
chore(meta/error): remove MetaStorageError::SerdeError
2 parents 97d4978 + db89a7d commit 7de3d3e

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

src/meta/sled-store/src/sled_tree.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ impl SledTree {
130130
MetaStorageError::BytesError(_e) => {
131131
Err(ConflictableTransactionError::Abort(meta_sto_err))
132132
}
133-
MetaStorageError::SerdeError(_e) => {
134-
Err(ConflictableTransactionError::Abort(meta_sto_err))
135-
}
136133
MetaStorageError::SledError(_e) => {
137134
Err(ConflictableTransactionError::Abort(meta_sto_err))
138135
}
@@ -152,7 +149,7 @@ impl SledTree {
152149
Err(txn_err) => match txn_err {
153150
TransactionError::Abort(meta_sto_err) => Err(meta_sto_err),
154151
TransactionError::Storage(sto_err) => {
155-
Err(MetaStorageError::SerdeError(sto_err.to_string()))
152+
Err(MetaStorageError::SledError(AnyError::new(&sto_err)))
156153
}
157154
},
158155
}

src/meta/types/src/meta_storage_errors.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@ use crate::error_context::ErrorWithContext;
2222

2323
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, thiserror::Error)]
2424
pub enum MetaStorageError {
25-
// type to represent bytes format errors
26-
#[error("{0}")]
27-
BytesError(String),
28-
29-
// type to represent serialize/deserialize errors
30-
#[error("{0}")]
31-
SerdeError(String),
25+
/// An error raised when encode/decode data to/from underlying storage.
26+
#[error(transparent)]
27+
BytesError(AnyError),
3228

3329
/// An AnyError built from sled::Error.
3430
#[error(transparent)]
@@ -43,7 +39,7 @@ pub enum MetaStorageError {
4339
TransactionConflict,
4440
}
4541

46-
pub type MetaStorageResult<T> = std::result::Result<T, MetaStorageError>;
42+
pub type MetaStorageResult<T> = Result<T, MetaStorageError>;
4743

4844
impl From<MetaStorageError> for ErrorCode {
4945
fn from(e: MetaStorageError) -> Self {
@@ -53,17 +49,13 @@ impl From<MetaStorageError> for ErrorCode {
5349

5450
impl From<std::string::FromUtf8Error> for MetaStorageError {
5551
fn from(error: std::string::FromUtf8Error) -> Self {
56-
MetaStorageError::BytesError(format!(
57-
"Bad bytes, cannot parse bytes with UTF8, cause: {}",
58-
error
59-
))
52+
MetaStorageError::BytesError(AnyError::new(&error))
6053
}
6154
}
6255

63-
// from serde error to MetaStorageError::SerdeError
6456
impl From<serde_json::Error> for MetaStorageError {
6557
fn from(error: serde_json::Error) -> MetaStorageError {
66-
MetaStorageError::SerdeError(format!("serde json se/de error: {:?}", error))
58+
MetaStorageError::BytesError(AnyError::new(&error))
6759
}
6860
}
6961

0 commit comments

Comments
 (0)