@@ -22,13 +22,9 @@ use crate::error_context::ErrorWithContext;
22
22
23
23
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , thiserror:: Error ) ]
24
24
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 ) ,
32
28
33
29
/// An AnyError built from sled::Error.
34
30
#[ error( transparent) ]
@@ -43,7 +39,7 @@ pub enum MetaStorageError {
43
39
TransactionConflict ,
44
40
}
45
41
46
- pub type MetaStorageResult < T > = std :: result :: Result < T , MetaStorageError > ;
42
+ pub type MetaStorageResult < T > = Result < T , MetaStorageError > ;
47
43
48
44
impl From < MetaStorageError > for ErrorCode {
49
45
fn from ( e : MetaStorageError ) -> Self {
@@ -53,17 +49,13 @@ impl From<MetaStorageError> for ErrorCode {
53
49
54
50
impl From < std:: string:: FromUtf8Error > for MetaStorageError {
55
51
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) )
60
53
}
61
54
}
62
55
63
- // from serde error to MetaStorageError::SerdeError
64
56
impl From < serde_json:: Error > for MetaStorageError {
65
57
fn from ( error : serde_json:: Error ) -> MetaStorageError {
66
- MetaStorageError :: SerdeError ( format ! ( "serde json se/de error: {:?}" , error) )
58
+ MetaStorageError :: BytesError ( AnyError :: new ( & error) )
67
59
}
68
60
}
69
61
0 commit comments