@@ -18,7 +18,7 @@ use crate::{
1818 sdam:: { ServerType , TopologyVersion } ,
1919} ;
2020
21- pub use bulk_write:: BulkWriteError as ClientBulkWriteError ;
21+ pub use bulk_write:: BulkWriteError ;
2222
2323const RECOVERING_CODES : [ i32 ; 5 ] = [ 11600 , 11602 , 13436 , 189 , 91 ] ;
2424const NOTWRITABLEPRIMARY_CODES : [ i32 ; 3 ] = [ 10107 , 13435 , 10058 ] ;
@@ -195,8 +195,8 @@ impl Error {
195195 fn is_write_concern_error ( & self ) -> bool {
196196 match * self . kind {
197197 ErrorKind :: Write ( WriteFailure :: WriteConcernError ( _) ) => true ,
198- ErrorKind :: BulkWrite ( ref bulk_write_error )
199- if bulk_write_error . write_concern_error . is_some ( ) =>
198+ ErrorKind :: InsertMany ( ref insert_many_error )
199+ if insert_many_error . write_concern_error . is_some ( ) =>
200200 {
201201 true
202202 }
@@ -249,7 +249,7 @@ impl Error {
249249 matches ! (
250250 self . kind. as_ref( ) ,
251251 ErrorKind :: Authentication { .. }
252- | ErrorKind :: BulkWrite ( _)
252+ | ErrorKind :: InsertMany ( _)
253253 | ErrorKind :: Command ( _)
254254 | ErrorKind :: Write ( _)
255255 )
@@ -308,7 +308,7 @@ impl Error {
308308 ErrorKind :: Command ( command_error) => Some ( command_error. code ) ,
309309 // According to SDAM spec, write concern error codes MUST also be checked, and
310310 // writeError codes MUST NOT be checked.
311- ErrorKind :: BulkWrite ( BulkWriteFailure {
311+ ErrorKind :: InsertMany ( InsertManyError {
312312 write_concern_error : Some ( wc_error) ,
313313 ..
314314 } ) => Some ( wc_error. code ) ,
@@ -323,7 +323,7 @@ impl Error {
323323 pub ( crate ) fn code ( & self ) -> Option < i32 > {
324324 match self . kind . as_ref ( ) {
325325 ErrorKind :: Command ( command_error) => Some ( command_error. code ) ,
326- ErrorKind :: BulkWrite ( BulkWriteFailure {
326+ ErrorKind :: InsertMany ( InsertManyError {
327327 write_concern_error : Some ( wc_error) ,
328328 ..
329329 } ) => Some ( wc_error. code ) ,
@@ -334,15 +334,15 @@ impl Error {
334334 }
335335
336336 /// Gets the message for this error, if applicable, for use in testing.
337- /// If this error is a BulkWriteError , the messages are concatenated.
337+ /// If this error is an InsertManyError , the messages are concatenated.
338338 #[ cfg( test) ]
339339 pub ( crate ) fn message ( & self ) -> Option < String > {
340340 match self . kind . as_ref ( ) {
341341 ErrorKind :: Command ( command_error) => Some ( command_error. message . clone ( ) ) ,
342342 // since this is used primarily for errorMessageContains assertions in the unified
343343 // runner, we just concatenate all the relevant server messages into one for
344- // bulk errors.
345- ErrorKind :: BulkWrite ( BulkWriteFailure {
344+ // insert many errors.
345+ ErrorKind :: InsertMany ( InsertManyError {
346346 write_concern_error,
347347 write_errors,
348348 inserted_ids : _,
@@ -382,7 +382,7 @@ impl Error {
382382 WriteFailure :: WriteConcernError ( ref wce) => Some ( wce. code_name . as_str ( ) ) ,
383383 WriteFailure :: WriteError ( ref we) => we. code_name . as_deref ( ) ,
384384 } ,
385- ErrorKind :: BulkWrite ( ref bwe) => bwe
385+ ErrorKind :: InsertMany ( ref bwe) => bwe
386386 . write_concern_error
387387 . as_ref ( )
388388 . map ( |wce| wce. code_name . as_str ( ) ) ,
@@ -481,21 +481,21 @@ impl Error {
481481 // This is intentionally written without a catch-all branch so that if new error
482482 // kinds are added we remember to reason about whether they need to be redacted.
483483 match * self . kind {
484- ErrorKind :: BulkWrite ( ref mut bwe ) => {
485- if let Some ( ref mut wes) = bwe . write_errors {
484+ ErrorKind :: InsertMany ( ref mut insert_many_error ) => {
485+ if let Some ( ref mut wes) = insert_many_error . write_errors {
486486 for we in wes {
487487 we. redact ( ) ;
488488 }
489489 }
490- if let Some ( ref mut wce) = bwe . write_concern_error {
490+ if let Some ( ref mut wce) = insert_many_error . write_concern_error {
491491 wce. redact ( ) ;
492492 }
493493 }
494- ErrorKind :: ClientBulkWrite ( ref mut client_bulk_write_error ) => {
495- for write_concern_error in client_bulk_write_error . write_concern_errors . iter_mut ( ) {
494+ ErrorKind :: BulkWrite ( ref mut bulk_write_error ) => {
495+ for write_concern_error in bulk_write_error . write_concern_errors . iter_mut ( ) {
496496 write_concern_error. redact ( ) ;
497497 }
498- for ( _, write_error) in client_bulk_write_error . write_errors . iter_mut ( ) {
498+ for ( _, write_error) in bulk_write_error . write_errors . iter_mut ( ) {
499499 write_error. redact ( ) ;
500500 }
501501 }
@@ -612,12 +612,13 @@ pub enum ErrorKind {
612612 #[ error( "{0}" ) ]
613613 BsonSerialization ( crate :: bson:: ser:: Error ) ,
614614
615- /// An error occurred when trying to execute a write operation consisting of multiple writes.
616- #[ error( "An error occurred when trying to execute a write operation: {0:?}" ) ]
617- BulkWrite ( BulkWriteFailure ) ,
615+ /// An error occurred when trying to execute an [`insert_many`](crate::Collection::insert_many)
616+ /// operation.
617+ #[ error( "An error occurred when trying to execute an insert_many operation: {0:?}" ) ]
618+ InsertMany ( InsertManyError ) ,
618619
619620 #[ error( "An error occurred when executing Client::bulk_write: {0:?}" ) ]
620- ClientBulkWrite ( ClientBulkWriteError ) ,
621+ BulkWrite ( BulkWriteError ) ,
621622
622623 /// The server returned an error to an attempted operation.
623624 #[ error( "Command failed: {0}" ) ]
@@ -706,7 +707,7 @@ impl ErrorKind {
706707 // TODO CLOUDP-105256 Remove this when Atlas Proxy error label behavior is fixed.
707708 fn get_write_concern_error ( & self ) -> Option < & WriteConcernError > {
708709 match self {
709- ErrorKind :: BulkWrite ( BulkWriteFailure {
710+ ErrorKind :: InsertMany ( InsertManyError {
710711 write_concern_error,
711712 ..
712713 } ) => write_concern_error. as_ref ( ) ,
@@ -825,11 +826,11 @@ impl WriteError {
825826 }
826827}
827828
828- /// An error that occurred during a write operation consisting of multiple writes that wasn't due to
829- /// being unable to satisfy a write concern .
829+ /// An individual write error that occurred during an
830+ /// [`insert_many`](crate::Collection::insert_many) operation .
830831#[ derive( Debug , PartialEq , Clone , Serialize , Deserialize ) ]
831832#[ non_exhaustive]
832- pub struct BulkWriteError {
833+ pub struct IndexedWriteError {
833834 /// Index into the list of operations that this error corresponds to.
834835 #[ serde( default ) ]
835836 pub index : usize ,
@@ -854,22 +855,23 @@ pub struct BulkWriteError {
854855 pub details : Option < Document > ,
855856}
856857
857- impl BulkWriteError {
858- // If any new fields are added to BulkWriteError , this implementation must be updated to redact
858+ impl IndexedWriteError {
859+ // If any new fields are added to InsertError , this implementation must be updated to redact
859860 // them per the CLAM spec.
860861 fn redact ( & mut self ) {
861862 self . message = "REDACTED" . to_string ( ) ;
862863 self . details = None ;
863864 }
864865}
865866
866- /// The set of errors that occurred during a write operation.
867+ /// The set of errors that occurred during a call to
868+ /// [`insert_many`](crate::Collection::insert_many).
867869#[ derive( Clone , Debug , Serialize , Deserialize ) ]
868870#[ serde( rename_all = "camelCase" ) ]
869871#[ non_exhaustive]
870- pub struct BulkWriteFailure {
872+ pub struct InsertManyError {
871873 /// The error(s) that occurred on account of a non write concern failure.
872- pub write_errors : Option < Vec < BulkWriteError > > ,
874+ pub write_errors : Option < Vec < IndexedWriteError > > ,
873875
874876 /// The error that occurred on account of write concern failure.
875877 pub write_concern_error : Option < WriteConcernError > ,
@@ -878,9 +880,9 @@ pub struct BulkWriteFailure {
878880 pub ( crate ) inserted_ids : HashMap < usize , Bson > ,
879881}
880882
881- impl BulkWriteFailure {
883+ impl InsertManyError {
882884 pub ( crate ) fn new ( ) -> Self {
883- BulkWriteFailure {
885+ InsertManyError {
884886 write_errors : None ,
885887 write_concern_error : None ,
886888 inserted_ids : Default :: default ( ) ,
@@ -901,13 +903,13 @@ pub enum WriteFailure {
901903}
902904
903905impl WriteFailure {
904- fn from_bulk_failure ( bulk : BulkWriteFailure ) -> Result < Self > {
905- if let Some ( bulk_write_error ) = bulk. write_errors . and_then ( |es| es. into_iter ( ) . next ( ) ) {
906+ fn from_insert_many_error ( bulk : InsertManyError ) -> Result < Self > {
907+ if let Some ( insert_error ) = bulk. write_errors . and_then ( |es| es. into_iter ( ) . next ( ) ) {
906908 let write_error = WriteError {
907- code : bulk_write_error . code ,
908- code_name : bulk_write_error . code_name ,
909- message : bulk_write_error . message ,
910- details : bulk_write_error . details ,
909+ code : insert_error . code ,
910+ code_name : insert_error . code_name ,
911+ message : insert_error . message ,
912+ details : insert_error . details ,
911913 } ;
912914 Ok ( WriteFailure :: WriteError ( write_error) )
913915 } else if let Some ( wc_error) = bulk. write_concern_error {
@@ -993,14 +995,15 @@ pub enum GridFsFileIdentifier {
993995 Id ( Bson ) ,
994996}
995997
996- /// Translates ErrorKind::BulkWriteError cases to ErrorKind::WriteErrors, leaving all other errors
997- /// untouched.
998- pub ( crate ) fn convert_bulk_errors ( error : Error ) -> Error {
998+ /// Translates ErrorKind::InsertMany to ErrorKind::Write, leaving all other errors untouched.
999+ pub ( crate ) fn convert_insert_many_error ( error : Error ) -> Error {
9991000 match * error. kind {
1000- ErrorKind :: BulkWrite ( bulk_failure) => match WriteFailure :: from_bulk_failure ( bulk_failure) {
1001- Ok ( failure) => Error :: new ( ErrorKind :: Write ( failure) , Some ( error. labels ) ) ,
1002- Err ( e) => e,
1003- } ,
1001+ ErrorKind :: InsertMany ( insert_many_error) => {
1002+ match WriteFailure :: from_insert_many_error ( insert_many_error) {
1003+ Ok ( failure) => Error :: new ( ErrorKind :: Write ( failure) , Some ( error. labels ) ) ,
1004+ Err ( e) => e,
1005+ }
1006+ }
10041007 _ => error,
10051008 }
10061009}
0 commit comments