@@ -18,7 +18,7 @@ use crate::{
18
18
sdam:: { ServerType , TopologyVersion } ,
19
19
} ;
20
20
21
- pub use bulk_write:: BulkWriteError as ClientBulkWriteError ;
21
+ pub use bulk_write:: BulkWriteError ;
22
22
23
23
const RECOVERING_CODES : [ i32 ; 5 ] = [ 11600 , 11602 , 13436 , 189 , 91 ] ;
24
24
const NOTWRITABLEPRIMARY_CODES : [ i32 ; 3 ] = [ 10107 , 13435 , 10058 ] ;
@@ -195,8 +195,8 @@ impl Error {
195
195
fn is_write_concern_error ( & self ) -> bool {
196
196
match * self . kind {
197
197
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 ( ) =>
200
200
{
201
201
true
202
202
}
@@ -249,7 +249,7 @@ impl Error {
249
249
matches ! (
250
250
self . kind. as_ref( ) ,
251
251
ErrorKind :: Authentication { .. }
252
- | ErrorKind :: BulkWrite ( _)
252
+ | ErrorKind :: InsertMany ( _)
253
253
| ErrorKind :: Command ( _)
254
254
| ErrorKind :: Write ( _)
255
255
)
@@ -308,7 +308,7 @@ impl Error {
308
308
ErrorKind :: Command ( command_error) => Some ( command_error. code ) ,
309
309
// According to SDAM spec, write concern error codes MUST also be checked, and
310
310
// writeError codes MUST NOT be checked.
311
- ErrorKind :: BulkWrite ( BulkWriteFailure {
311
+ ErrorKind :: InsertMany ( InsertManyError {
312
312
write_concern_error : Some ( wc_error) ,
313
313
..
314
314
} ) => Some ( wc_error. code ) ,
@@ -323,7 +323,7 @@ impl Error {
323
323
pub ( crate ) fn code ( & self ) -> Option < i32 > {
324
324
match self . kind . as_ref ( ) {
325
325
ErrorKind :: Command ( command_error) => Some ( command_error. code ) ,
326
- ErrorKind :: BulkWrite ( BulkWriteFailure {
326
+ ErrorKind :: InsertMany ( InsertManyError {
327
327
write_concern_error : Some ( wc_error) ,
328
328
..
329
329
} ) => Some ( wc_error. code ) ,
@@ -334,15 +334,15 @@ impl Error {
334
334
}
335
335
336
336
/// 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.
338
338
#[ cfg( test) ]
339
339
pub ( crate ) fn message ( & self ) -> Option < String > {
340
340
match self . kind . as_ref ( ) {
341
341
ErrorKind :: Command ( command_error) => Some ( command_error. message . clone ( ) ) ,
342
342
// since this is used primarily for errorMessageContains assertions in the unified
343
343
// 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 {
346
346
write_concern_error,
347
347
write_errors,
348
348
inserted_ids : _,
@@ -382,7 +382,7 @@ impl Error {
382
382
WriteFailure :: WriteConcernError ( ref wce) => Some ( wce. code_name . as_str ( ) ) ,
383
383
WriteFailure :: WriteError ( ref we) => we. code_name . as_deref ( ) ,
384
384
} ,
385
- ErrorKind :: BulkWrite ( ref bwe) => bwe
385
+ ErrorKind :: InsertMany ( ref bwe) => bwe
386
386
. write_concern_error
387
387
. as_ref ( )
388
388
. map ( |wce| wce. code_name . as_str ( ) ) ,
@@ -481,21 +481,21 @@ impl Error {
481
481
// This is intentionally written without a catch-all branch so that if new error
482
482
// kinds are added we remember to reason about whether they need to be redacted.
483
483
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 {
486
486
for we in wes {
487
487
we. redact ( ) ;
488
488
}
489
489
}
490
- if let Some ( ref mut wce) = bwe . write_concern_error {
490
+ if let Some ( ref mut wce) = insert_many_error . write_concern_error {
491
491
wce. redact ( ) ;
492
492
}
493
493
}
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 ( ) {
496
496
write_concern_error. redact ( ) ;
497
497
}
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 ( ) {
499
499
write_error. redact ( ) ;
500
500
}
501
501
}
@@ -612,12 +612,13 @@ pub enum ErrorKind {
612
612
#[ error( "{0}" ) ]
613
613
BsonSerialization ( crate :: bson:: ser:: Error ) ,
614
614
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 ) ,
618
619
619
620
#[ error( "An error occurred when executing Client::bulk_write: {0:?}" ) ]
620
- ClientBulkWrite ( ClientBulkWriteError ) ,
621
+ BulkWrite ( BulkWriteError ) ,
621
622
622
623
/// The server returned an error to an attempted operation.
623
624
#[ error( "Command failed: {0}" ) ]
@@ -706,7 +707,7 @@ impl ErrorKind {
706
707
// TODO CLOUDP-105256 Remove this when Atlas Proxy error label behavior is fixed.
707
708
fn get_write_concern_error ( & self ) -> Option < & WriteConcernError > {
708
709
match self {
709
- ErrorKind :: BulkWrite ( BulkWriteFailure {
710
+ ErrorKind :: InsertMany ( InsertManyError {
710
711
write_concern_error,
711
712
..
712
713
} ) => write_concern_error. as_ref ( ) ,
@@ -825,11 +826,11 @@ impl WriteError {
825
826
}
826
827
}
827
828
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 .
830
831
#[ derive( Debug , PartialEq , Clone , Serialize , Deserialize ) ]
831
832
#[ non_exhaustive]
832
- pub struct BulkWriteError {
833
+ pub struct IndexedWriteError {
833
834
/// Index into the list of operations that this error corresponds to.
834
835
#[ serde( default ) ]
835
836
pub index : usize ,
@@ -854,22 +855,23 @@ pub struct BulkWriteError {
854
855
pub details : Option < Document > ,
855
856
}
856
857
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
859
860
// them per the CLAM spec.
860
861
fn redact ( & mut self ) {
861
862
self . message = "REDACTED" . to_string ( ) ;
862
863
self . details = None ;
863
864
}
864
865
}
865
866
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).
867
869
#[ derive( Clone , Debug , Serialize , Deserialize ) ]
868
870
#[ serde( rename_all = "camelCase" ) ]
869
871
#[ non_exhaustive]
870
- pub struct BulkWriteFailure {
872
+ pub struct InsertManyError {
871
873
/// 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 > > ,
873
875
874
876
/// The error that occurred on account of write concern failure.
875
877
pub write_concern_error : Option < WriteConcernError > ,
@@ -878,9 +880,9 @@ pub struct BulkWriteFailure {
878
880
pub ( crate ) inserted_ids : HashMap < usize , Bson > ,
879
881
}
880
882
881
- impl BulkWriteFailure {
883
+ impl InsertManyError {
882
884
pub ( crate ) fn new ( ) -> Self {
883
- BulkWriteFailure {
885
+ InsertManyError {
884
886
write_errors : None ,
885
887
write_concern_error : None ,
886
888
inserted_ids : Default :: default ( ) ,
@@ -901,13 +903,13 @@ pub enum WriteFailure {
901
903
}
902
904
903
905
impl 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 ( ) ) {
906
908
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 ,
911
913
} ;
912
914
Ok ( WriteFailure :: WriteError ( write_error) )
913
915
} else if let Some ( wc_error) = bulk. write_concern_error {
@@ -993,14 +995,15 @@ pub enum GridFsFileIdentifier {
993
995
Id ( Bson ) ,
994
996
}
995
997
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 {
999
1000
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
+ }
1004
1007
_ => error,
1005
1008
}
1006
1009
}
0 commit comments