1
1
use std:: path:: PathBuf ;
2
+ use std:: sync:: Arc ;
2
3
use std:: { fmt, io} ;
3
4
4
5
use crate :: Version ;
5
6
6
7
/// Error while trying to acquire a directory lock.
7
- #[ derive( Debug , Error ) ]
8
+ #[ derive( Debug , Clone , Error ) ]
8
9
pub enum LockError {
9
10
/// Failed to acquired a lock as it is already held by another
10
11
/// client.
@@ -16,11 +17,18 @@ pub enum LockError {
16
17
LockBusy ,
17
18
/// Trying to acquire a lock failed with an `IoError`
18
19
#[ error( "Failed to acquire the lock due to an io:Error." ) ]
19
- IoError ( io:: Error ) ,
20
+ IoError ( Arc < io:: Error > ) ,
21
+ }
22
+
23
+ impl LockError {
24
+ /// Wraps an io error.
25
+ pub fn wrap_io_error ( io_error : io:: Error ) -> Self {
26
+ Self :: IoError ( Arc :: new ( io_error) )
27
+ }
20
28
}
21
29
22
30
/// Error that may occur when opening a directory
23
- #[ derive( Debug , Error ) ]
31
+ #[ derive( Debug , Clone , Error ) ]
24
32
pub enum OpenDirectoryError {
25
33
/// The underlying directory does not exists.
26
34
#[ error( "Directory does not exist: '{0}'." ) ]
@@ -30,12 +38,12 @@ pub enum OpenDirectoryError {
30
38
NotADirectory ( PathBuf ) ,
31
39
/// Failed to create a temp directory.
32
40
#[ error( "Failed to create a temporary directory: '{0}'." ) ]
33
- FailedToCreateTempDir ( io:: Error ) ,
41
+ FailedToCreateTempDir ( Arc < io:: Error > ) ,
34
42
/// IoError
35
43
#[ error( "IoError '{io_error:?}' while create directory in: '{directory_path:?}'." ) ]
36
44
IoError {
37
45
/// underlying io Error.
38
- io_error : io:: Error ,
46
+ io_error : Arc < io:: Error > ,
39
47
/// directory we tried to open.
40
48
directory_path : PathBuf ,
41
49
} ,
@@ -45,14 +53,14 @@ impl OpenDirectoryError {
45
53
/// Wraps an io error.
46
54
pub fn wrap_io_error ( io_error : io:: Error , directory_path : PathBuf ) -> Self {
47
55
Self :: IoError {
48
- io_error,
56
+ io_error : Arc :: new ( io_error ) ,
49
57
directory_path,
50
58
}
51
59
}
52
60
}
53
61
54
62
/// Error that may occur when starting to write in a file
55
- #[ derive( Debug , Error ) ]
63
+ #[ derive( Debug , Clone , Error ) ]
56
64
pub enum OpenWriteError {
57
65
/// Our directory is WORM, writing an existing file is forbidden.
58
66
/// Checkout the `Directory` documentation.
@@ -63,7 +71,7 @@ pub enum OpenWriteError {
63
71
#[ error( "IoError '{io_error:?}' while opening file for write: '{filepath}'." ) ]
64
72
IoError {
65
73
/// The underlying `io::Error`.
66
- io_error : io:: Error ,
74
+ io_error : Arc < io:: Error > ,
67
75
/// File path of the file that tantivy failed to open for write.
68
76
filepath : PathBuf ,
69
77
} ,
@@ -72,11 +80,15 @@ pub enum OpenWriteError {
72
80
impl OpenWriteError {
73
81
/// Wraps an io error.
74
82
pub fn wrap_io_error ( io_error : io:: Error , filepath : PathBuf ) -> Self {
75
- Self :: IoError { io_error, filepath }
83
+ Self :: IoError {
84
+ io_error : Arc :: new ( io_error) ,
85
+ filepath,
86
+ }
76
87
}
77
88
}
78
89
/// Type of index incompatibility between the library and the index found on disk
79
90
/// Used to catch and provide a hint to solve this incompatibility issue
91
+ #[ derive( Clone ) ]
80
92
pub enum Incompatibility {
81
93
/// This library cannot decompress the index found on disk
82
94
CompressionMismatch {
@@ -135,7 +147,7 @@ impl fmt::Debug for Incompatibility {
135
147
}
136
148
137
149
/// Error that may occur when accessing a file read
138
- #[ derive( Debug , Error ) ]
150
+ #[ derive( Debug , Clone , Error ) ]
139
151
pub enum OpenReadError {
140
152
/// The file does not exists.
141
153
#[ error( "Files does not exists: {0:?}" ) ]
@@ -146,7 +158,7 @@ pub enum OpenReadError {
146
158
) ]
147
159
IoError {
148
160
/// The underlying `io::Error`.
149
- io_error : io:: Error ,
161
+ io_error : Arc < io:: Error > ,
150
162
/// File path of the file that tantivy failed to open for read.
151
163
filepath : PathBuf ,
152
164
} ,
@@ -158,11 +170,14 @@ pub enum OpenReadError {
158
170
impl OpenReadError {
159
171
/// Wraps an io error.
160
172
pub fn wrap_io_error ( io_error : io:: Error , filepath : PathBuf ) -> Self {
161
- Self :: IoError { io_error, filepath }
173
+ Self :: IoError {
174
+ io_error : Arc :: new ( io_error) ,
175
+ filepath,
176
+ }
162
177
}
163
178
}
164
179
/// Error that may occur when trying to delete a file
165
- #[ derive( Debug , Error ) ]
180
+ #[ derive( Debug , Clone , Error ) ]
166
181
pub enum DeleteError {
167
182
/// The file does not exists.
168
183
#[ error( "File does not exists: '{0}'." ) ]
@@ -172,7 +187,7 @@ pub enum DeleteError {
172
187
#[ error( "The following IO error happened while deleting file '{filepath}': '{io_error:?}'." ) ]
173
188
IoError {
174
189
/// The underlying `io::Error`.
175
- io_error : io:: Error ,
190
+ io_error : Arc < io:: Error > ,
176
191
/// File path of the file that tantivy failed to delete.
177
192
filepath : PathBuf ,
178
193
} ,
0 commit comments