@@ -158,15 +158,15 @@ impl Error {
158158 }
159159
160160 pub ( crate ) fn is_max_time_ms_expired_error ( & self ) -> bool {
161- self . code ( ) == Some ( 50 )
161+ self . sdam_code ( ) == Some ( 50 )
162162 }
163163
164164 /// Whether a read operation should be retried if this error occurs.
165165 pub ( crate ) fn is_read_retryable ( & self ) -> bool {
166166 if self . is_network_error ( ) {
167167 return true ;
168168 }
169- match self . code ( ) {
169+ match self . sdam_code ( ) {
170170 Some ( code) => RETRYABLE_READ_CODES . contains ( & code) ,
171171 None => false ,
172172 }
@@ -187,7 +187,7 @@ impl Error {
187187 if self . is_network_error ( ) {
188188 return true ;
189189 }
190- match & self . code ( ) {
190+ match & self . sdam_code ( ) {
191191 Some ( code) => RETRYABLE_WRITE_CODES . contains ( code) ,
192192 None => false ,
193193 }
@@ -201,7 +201,7 @@ impl Error {
201201 {
202202 return true ;
203203 }
204- match self . code ( ) {
204+ match self . sdam_code ( ) {
205205 Some ( code) => UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL_CODES . contains ( & code) ,
206206 None => false ,
207207 }
@@ -259,7 +259,7 @@ impl Error {
259259
260260 /// Gets the code from this error for performing SDAM updates, if applicable.
261261 /// Any codes contained in WriteErrors are ignored.
262- pub ( crate ) fn code ( & self ) -> Option < i32 > {
262+ pub ( crate ) fn sdam_code ( & self ) -> Option < i32 > {
263263 match self . kind . as_ref ( ) {
264264 ErrorKind :: Command ( command_error) => Some ( command_error. code ) ,
265265 // According to SDAM spec, write concern error codes MUST also be checked, and
@@ -271,7 +271,22 @@ impl Error {
271271 ErrorKind :: Write ( WriteFailure :: WriteConcernError ( wc_error) ) => Some ( wc_error. code ) ,
272272 _ => None ,
273273 }
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 ( ) ) )
275290 }
276291
277292 /// Gets the message for this error, if applicable, for use in testing.
@@ -333,21 +348,21 @@ impl Error {
333348
334349 /// If this error corresponds to a "not writable primary" error as per the SDAM spec.
335350 pub ( crate ) fn is_notwritableprimary ( & self ) -> bool {
336- self . code ( )
351+ self . sdam_code ( )
337352 . map ( |code| NOTWRITABLEPRIMARY_CODES . contains ( & code) )
338353 . unwrap_or ( false )
339354 }
340355
341356 /// If this error corresponds to a "node is recovering" error as per the SDAM spec.
342357 pub ( crate ) fn is_recovering ( & self ) -> bool {
343- self . code ( )
358+ self . sdam_code ( )
344359 . map ( |code| RECOVERING_CODES . contains ( & code) )
345360 . unwrap_or ( false )
346361 }
347362
348363 /// If this error corresponds to a "node is shutting down" error as per the SDAM spec.
349364 pub ( crate ) fn is_shutting_down ( & self ) -> bool {
350- self . code ( )
365+ self . sdam_code ( )
351366 . map ( |code| SHUTTING_DOWN_CODES . contains ( & code) )
352367 . unwrap_or ( false )
353368 }
@@ -361,7 +376,7 @@ impl Error {
361376 if !self . is_server_error ( ) {
362377 return true ;
363378 }
364- let code = self . code ( ) ;
379+ let code = self . sdam_code ( ) ;
365380 if code == Some ( 43 ) {
366381 return true ;
367382 }
@@ -388,6 +403,11 @@ impl Error {
388403 matches ! ( self . kind. as_ref( ) , ErrorKind :: IncompatibleServer { .. } )
389404 }
390405
406+ #[ allow( unused) ]
407+ pub ( crate ) fn is_invalid_argument ( & self ) -> bool {
408+ matches ! ( self . kind. as_ref( ) , ErrorKind :: InvalidArgument { .. } )
409+ }
410+
391411 pub ( crate ) fn with_source < E : Into < Option < Error > > > ( mut self , source : E ) -> Self {
392412 self . source = source. into ( ) . map ( Box :: new) ;
393413 self
@@ -825,6 +845,13 @@ impl WriteFailure {
825845 . into ( ) )
826846 }
827847 }
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+ }
828855}
829856
830857/// An error that occurred during a GridFS operation.
0 commit comments