@@ -158,15 +158,15 @@ impl Error {
158
158
}
159
159
160
160
pub ( crate ) fn is_max_time_ms_expired_error ( & self ) -> bool {
161
- self . code ( ) == Some ( 50 )
161
+ self . sdam_code ( ) == Some ( 50 )
162
162
}
163
163
164
164
/// Whether a read operation should be retried if this error occurs.
165
165
pub ( crate ) fn is_read_retryable ( & self ) -> bool {
166
166
if self . is_network_error ( ) {
167
167
return true ;
168
168
}
169
- match self . code ( ) {
169
+ match self . sdam_code ( ) {
170
170
Some ( code) => RETRYABLE_READ_CODES . contains ( & code) ,
171
171
None => false ,
172
172
}
@@ -187,7 +187,7 @@ impl Error {
187
187
if self . is_network_error ( ) {
188
188
return true ;
189
189
}
190
- match & self . code ( ) {
190
+ match & self . sdam_code ( ) {
191
191
Some ( code) => RETRYABLE_WRITE_CODES . contains ( code) ,
192
192
None => false ,
193
193
}
@@ -201,7 +201,7 @@ impl Error {
201
201
{
202
202
return true ;
203
203
}
204
- match self . code ( ) {
204
+ match self . sdam_code ( ) {
205
205
Some ( code) => UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL_CODES . contains ( & code) ,
206
206
None => false ,
207
207
}
@@ -259,7 +259,7 @@ impl Error {
259
259
260
260
/// Gets the code from this error for performing SDAM updates, if applicable.
261
261
/// Any codes contained in WriteErrors are ignored.
262
- pub ( crate ) fn code ( & self ) -> Option < i32 > {
262
+ pub ( crate ) fn sdam_code ( & self ) -> Option < i32 > {
263
263
match self . kind . as_ref ( ) {
264
264
ErrorKind :: Command ( command_error) => Some ( command_error. code ) ,
265
265
// According to SDAM spec, write concern error codes MUST also be checked, and
@@ -271,7 +271,22 @@ impl Error {
271
271
ErrorKind :: Write ( WriteFailure :: WriteConcernError ( wc_error) ) => Some ( wc_error. code ) ,
272
272
_ => None ,
273
273
}
274
- . or_else ( || self . source . as_ref ( ) . and_then ( |s| s. code ( ) ) )
274
+ . or_else ( || self . source . as_ref ( ) . and_then ( |s| s. sdam_code ( ) ) )
275
+ }
276
+
277
+ /// Gets the code from this error.
278
+ #[ allow( unused) ]
279
+ pub ( crate ) fn code ( & self ) -> Option < i32 > {
280
+ match self . kind . as_ref ( ) {
281
+ ErrorKind :: Command ( command_error) => Some ( command_error. code ) ,
282
+ ErrorKind :: BulkWrite ( BulkWriteFailure {
283
+ write_concern_error : Some ( wc_error) ,
284
+ ..
285
+ } ) => Some ( wc_error. code ) ,
286
+ ErrorKind :: Write ( e) => Some ( e. code ( ) ) ,
287
+ _ => None ,
288
+ }
289
+ . or_else ( || self . source . as_ref ( ) . and_then ( |s| s. sdam_code ( ) ) )
275
290
}
276
291
277
292
/// Gets the message for this error, if applicable, for use in testing.
@@ -333,21 +348,21 @@ impl Error {
333
348
334
349
/// If this error corresponds to a "not writable primary" error as per the SDAM spec.
335
350
pub ( crate ) fn is_notwritableprimary ( & self ) -> bool {
336
- self . code ( )
351
+ self . sdam_code ( )
337
352
. map ( |code| NOTWRITABLEPRIMARY_CODES . contains ( & code) )
338
353
. unwrap_or ( false )
339
354
}
340
355
341
356
/// If this error corresponds to a "node is recovering" error as per the SDAM spec.
342
357
pub ( crate ) fn is_recovering ( & self ) -> bool {
343
- self . code ( )
358
+ self . sdam_code ( )
344
359
. map ( |code| RECOVERING_CODES . contains ( & code) )
345
360
. unwrap_or ( false )
346
361
}
347
362
348
363
/// If this error corresponds to a "node is shutting down" error as per the SDAM spec.
349
364
pub ( crate ) fn is_shutting_down ( & self ) -> bool {
350
- self . code ( )
365
+ self . sdam_code ( )
351
366
. map ( |code| SHUTTING_DOWN_CODES . contains ( & code) )
352
367
. unwrap_or ( false )
353
368
}
@@ -361,7 +376,7 @@ impl Error {
361
376
if !self . is_server_error ( ) {
362
377
return true ;
363
378
}
364
- let code = self . code ( ) ;
379
+ let code = self . sdam_code ( ) ;
365
380
if code == Some ( 43 ) {
366
381
return true ;
367
382
}
@@ -388,6 +403,11 @@ impl Error {
388
403
matches ! ( self . kind. as_ref( ) , ErrorKind :: IncompatibleServer { .. } )
389
404
}
390
405
406
+ #[ allow( unused) ]
407
+ pub ( crate ) fn is_invalid_argument ( & self ) -> bool {
408
+ matches ! ( self . kind. as_ref( ) , ErrorKind :: InvalidArgument { .. } )
409
+ }
410
+
391
411
pub ( crate ) fn with_source < E : Into < Option < Error > > > ( mut self , source : E ) -> Self {
392
412
self . source = source. into ( ) . map ( Box :: new) ;
393
413
self
@@ -825,6 +845,13 @@ impl WriteFailure {
825
845
. into ( ) )
826
846
}
827
847
}
848
+
849
+ pub ( crate ) fn code ( & self ) -> i32 {
850
+ match self {
851
+ Self :: WriteConcernError ( e) => e. code ,
852
+ Self :: WriteError ( e) => e. code ,
853
+ }
854
+ }
828
855
}
829
856
830
857
/// An error that occurred during a GridFS operation.
0 commit comments