@@ -35,16 +35,12 @@ pub struct Error {
35
35
}
36
36
37
37
impl Error {
38
- pub ( crate ) fn new ( e : Arc < ErrorKind > ) -> Error {
39
- Error {
40
- kind : e,
41
- labels : Vec :: new ( ) ,
42
- }
43
- }
44
-
45
38
pub ( crate ) fn pool_cleared_error ( address : & StreamAddress ) -> Self {
46
39
ErrorKind :: ConnectionPoolClearedError {
47
- message : format ! ( "Conneciton pool for {} cleared during operation execution" , address)
40
+ message : format ! (
41
+ "Connection pool for {} cleared during operation execution" ,
42
+ address
43
+ ) ,
48
44
}
49
45
. into ( )
50
46
}
@@ -68,20 +64,6 @@ impl Error {
68
64
Error :: authentication_error ( mechanism_name, "invalid server response" )
69
65
}
70
66
71
- /// Attempts to get the `std::io::Error` from this `Error`.
72
- /// If there are other references to the underlying `Arc`, or if the `ErrorKind` is not `Io`,
73
- /// then the original error is returned as a custom `std::io::Error`.
74
- pub ( crate ) fn into_io_error ( self ) -> std:: io:: Error {
75
- match Arc :: try_unwrap ( self . kind ) {
76
- Ok ( ErrorKind :: Io ( io_error) ) => io_error,
77
- Ok ( other_error_kind) => {
78
- let error: Error = other_error_kind. into ( ) ;
79
- std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , Box :: new ( error) )
80
- }
81
- Err ( e) => std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , Box :: new ( Error :: new ( e) ) ) ,
82
- }
83
- }
84
-
85
67
/// Whether this error is an "ns not found" error or not.
86
68
pub ( crate ) fn is_ns_not_found ( & self ) -> bool {
87
69
matches ! ( self . kind. as_ref( ) , ErrorKind :: CommandError ( err) if err. code == 26 )
@@ -129,10 +111,13 @@ impl Error {
129
111
130
112
/// Whether an error originated from the server.
131
113
pub ( crate ) fn is_server_error ( & self ) -> bool {
132
- matches ! ( self . kind. as_ref( ) , ErrorKind :: AuthenticationError { .. }
133
- | ErrorKind :: BulkWriteError ( _)
134
- | ErrorKind :: CommandError ( _)
135
- | ErrorKind :: WriteError ( _) )
114
+ matches ! (
115
+ self . kind. as_ref( ) ,
116
+ ErrorKind :: AuthenticationError { .. }
117
+ | ErrorKind :: BulkWriteError ( _)
118
+ | ErrorKind :: CommandError ( _)
119
+ | ErrorKind :: WriteError ( _)
120
+ )
136
121
}
137
122
138
123
/// Returns the labels for this error.
@@ -153,7 +138,9 @@ impl Error {
153
138
154
139
/// Whether this error contains the specified label.
155
140
pub fn contains_label < T : AsRef < str > > ( & self , label : T ) -> bool {
156
- self . labels ( ) . iter ( ) . any ( |actual_label| actual_label. as_str ( ) == label. as_ref ( ) )
141
+ self . labels ( )
142
+ . iter ( )
143
+ . any ( |actual_label| actual_label. as_str ( ) == label. as_ref ( ) )
157
144
}
158
145
159
146
/// Returns a copy of this Error with the specified label added.
@@ -334,7 +321,7 @@ pub enum ErrorKind {
334
321
/// A timeout occurred before a Tokio task could be completed.
335
322
#[ cfg( feature = "tokio-runtime" ) ]
336
323
#[ error( display = "{}" , _0) ]
337
- TokioTimeoutElapsed ( #[ error( source) ] tokio:: time:: Elapsed ) ,
324
+ TokioTimeoutElapsed ( #[ error( source) ] tokio:: time:: error :: Elapsed ) ,
338
325
339
326
#[ error( display = "{}" , _0) ]
340
327
RustlsConfig ( #[ error( source) ] rustls:: TLSError ) ,
@@ -372,7 +359,10 @@ impl ErrorKind {
372
359
}
373
360
374
361
pub ( crate ) fn is_network_error ( & self ) -> bool {
375
- matches ! ( self , ErrorKind :: Io ( ..) | ErrorKind :: ConnectionPoolClearedError { .. } )
362
+ matches ! (
363
+ self ,
364
+ ErrorKind :: Io ( ..) | ErrorKind :: ConnectionPoolClearedError { .. }
365
+ )
376
366
}
377
367
378
368
/// Gets the code/message tuple from this error, if applicable. In the case of write errors, the
@@ -396,13 +386,14 @@ impl ErrorKind {
396
386
pub ( crate ) fn code_name ( & self ) -> Option < & str > {
397
387
match self {
398
388
ErrorKind :: CommandError ( ref cmd_err) => Some ( cmd_err. code_name . as_str ( ) ) ,
399
- ErrorKind :: WriteError ( ref failure) => {
400
- match failure {
401
- WriteFailure :: WriteConcernError ( ref wce) => Some ( wce. code_name . as_str ( ) ) ,
402
- WriteFailure :: WriteError ( ref we) => we. code_name . as_deref ( ) ,
403
- }
404
- }
405
- ErrorKind :: BulkWriteError ( ref bwe) => bwe. write_concern_error . as_ref ( ) . map ( |wce| wce. code_name . as_str ( ) ) ,
389
+ ErrorKind :: WriteError ( ref failure) => match failure {
390
+ WriteFailure :: WriteConcernError ( ref wce) => Some ( wce. code_name . as_str ( ) ) ,
391
+ WriteFailure :: WriteError ( ref we) => we. code_name . as_deref ( ) ,
392
+ } ,
393
+ ErrorKind :: BulkWriteError ( ref bwe) => bwe
394
+ . write_concern_error
395
+ . as_ref ( )
396
+ . map ( |wce| wce. code_name . as_str ( ) ) ,
406
397
_ => None ,
407
398
}
408
399
}
0 commit comments