@@ -5,13 +5,7 @@ use std::{
55 io,
66} ;
77
8- #[ cfg( feature = "testing" ) ]
9- use backtrace:: Backtrace ;
10-
11- use crate :: {
12- pagecache:: { DiskPtr , PageView } ,
13- IVec ,
14- } ;
8+ use crate :: pagecache:: { DiskPtr , PageView } ;
159
1610/// The top-level result type for dealing with
1711/// fallible operations. The errors tend to
@@ -32,27 +26,21 @@ pub(crate) type CasResult<'a, R> =
3226
3327/// An Error type encapsulating various issues that may come up
3428/// in the operation of a `Db`.
35- #[ derive( Debug ) ]
29+ #[ derive( Debug , Clone , Copy ) ]
3630pub enum Error {
3731 /// The underlying collection no longer exists.
38- CollectionNotFound ( IVec ) ,
32+ CollectionNotFound ,
3933 /// The system has been used in an unsupported way.
40- Unsupported ( String ) ,
34+ Unsupported ( & ' static str ) ,
4135 /// An unexpected bug has happened. Please open an issue on github!
42- ReportableBug ( String ) ,
36+ ReportableBug ( & ' static str ) ,
4337 /// A read or write error has happened when interacting with the file
4438 /// system.
45- Io ( io:: Error ) ,
39+ Io ( io:: ErrorKind , & ' static str ) ,
4640 /// Corruption has been detected in the storage file.
4741 Corruption {
4842 /// The file location that corrupted data was found at.
4943 at : Option < DiskPtr > ,
50- /// A backtrace for where the corruption was encountered.
51- #[ cfg( feature = "testing" ) ]
52- bt : Backtrace ,
53- /// A backtrace for where the corruption was encountered.
54- #[ cfg( not( feature = "testing" ) ) ]
55- bt : ( ) ,
5644 } ,
5745 // a failpoint has been triggered for testing purposes
5846 #[ doc( hidden) ]
@@ -62,29 +50,7 @@ pub enum Error {
6250
6351impl Error {
6452 pub ( crate ) fn corruption ( at : Option < DiskPtr > ) -> Error {
65- Error :: Corruption {
66- at,
67- #[ cfg( feature = "testing" ) ]
68- bt : Backtrace :: new ( ) ,
69- #[ cfg( not( feature = "testing" ) ) ]
70- bt : ( ) ,
71- }
72- }
73- }
74-
75- impl Clone for Error {
76- fn clone ( & self ) -> Self {
77- use self :: Error :: * ;
78-
79- match self {
80- Io ( ioe) => Io ( io:: Error :: new ( ioe. kind ( ) , format ! ( "{:?}" , ioe) ) ) ,
81- CollectionNotFound ( name) => CollectionNotFound ( name. clone ( ) ) ,
82- Unsupported ( why) => Unsupported ( why. clone ( ) ) ,
83- ReportableBug ( what) => ReportableBug ( what. clone ( ) ) ,
84- Corruption { at, bt } => Corruption { at : * at, bt : bt. clone ( ) } ,
85- #[ cfg( feature = "failpoints" ) ]
86- FailPoint => FailPoint ,
87- }
53+ Error :: Corruption { at }
8854 }
8955}
9056
@@ -95,13 +61,7 @@ impl PartialEq for Error {
9561 use self :: Error :: * ;
9662
9763 match * self {
98- CollectionNotFound ( ref l) => {
99- if let CollectionNotFound ( ref r) = * other {
100- l == r
101- } else {
102- false
103- }
104- }
64+ CollectionNotFound => CollectionNotFound == * other,
10565 Unsupported ( ref l) => {
10666 if let Unsupported ( ref r) = * other {
10767 l == r
@@ -127,15 +87,15 @@ impl PartialEq for Error {
12787 false
12888 }
12989 }
130- Io ( _) => false ,
90+ Io ( _, _ ) => false ,
13191 }
13292 }
13393}
13494
13595impl From < io:: Error > for Error {
13696 #[ inline]
13797 fn from ( io_error : io:: Error ) -> Self {
138- Error :: Io ( io_error)
98+ Error :: Io ( io_error. kind ( ) , "io error" )
13999 }
140100}
141101
@@ -144,10 +104,10 @@ impl From<Error> for io::Error {
144104 use self :: Error :: * ;
145105 use std:: io:: ErrorKind ;
146106 match error {
147- Io ( ioe ) => ioe ,
148- CollectionNotFound ( name ) => io:: Error :: new (
107+ Io ( kind , reason ) => io :: Error :: new ( kind , reason ) ,
108+ CollectionNotFound => io:: Error :: new (
149109 ErrorKind :: NotFound ,
150- format ! ( "collection not found: {:?}" , name ) ,
110+ "collection not found"
151111 ) ,
152112 Unsupported ( why) => io:: Error :: new (
153113 ErrorKind :: InvalidInput ,
@@ -180,8 +140,8 @@ impl Display for Error {
180140 use self :: Error :: * ;
181141
182142 match * self {
183- CollectionNotFound ( ref name ) => {
184- write ! ( f, "Collection {:?} does not exist" , name , )
143+ CollectionNotFound => {
144+ write ! ( f, "Collection does not exist" )
185145 }
186146 Unsupported ( ref e) => write ! ( f, "Unsupported: {}" , e) ,
187147 ReportableBug ( ref e) => write ! (
@@ -192,12 +152,12 @@ impl Display for Error {
192152 ) ,
193153 #[ cfg( feature = "failpoints" ) ]
194154 FailPoint => write ! ( f, "Fail point has been triggered." ) ,
195- Io ( ref e ) => write ! ( f , "IO error: {}" , e ) ,
196- Corruption { at , ref bt } => write ! (
197- f ,
198- "Read corrupted data at file offset {:?} backtrace {:?}" ,
199- at , bt
200- ) ,
155+ Io ( ref kind , ref reason ) => {
156+ write ! ( f , "IO error: ({:?}, {})" , kind , reason )
157+ }
158+ Corruption { at } => {
159+ write ! ( f , "Read corrupted data at file offset {:?}" , at )
160+ }
201161 }
202162 }
203163}
0 commit comments