@@ -119,6 +119,28 @@ mongoc_bulk_operation_destroy (mongoc_bulk_operation_t *bulk) /* IN */
119
119
(((_write_cmd->type) == (_write_cmd_type)) && \
120
120
(_write_cmd)->n_documents < MONGOC_DEFAULT_WRITE_BATCH_SIZE)
121
121
122
+ /* already failed, e.g. a bad call to mongoc_bulk_operation_insert? */
123
+ #define BULK_EXIT_IF_PRIOR_ERROR \
124
+ do { \
125
+ if (bulk->result.error.domain) { \
126
+ EXIT; \
127
+ } \
128
+ } while (0)
129
+
130
+ #define BULK_RETURN_IF_PRIOR_ERROR \
131
+ do { \
132
+ if (bulk->result.error.domain) {\
133
+ if (error != &bulk->result.error) {\
134
+ bson_set_error (error, \
135
+ MONGOC_ERROR_COMMAND, \
136
+ MONGOC_ERROR_COMMAND_INVALID_ARG, \
137
+ "Bulk operation is invalid from prior error: %s", \
138
+ bulk->result.error.message); \
139
+ }; \
140
+ return false; \
141
+ }; \
142
+ } while (0)
143
+
122
144
123
145
bool
124
146
_mongoc_bulk_operation_remove_with_opts (mongoc_bulk_operation_t * bulk ,
@@ -134,10 +156,7 @@ _mongoc_bulk_operation_remove_with_opts (mongoc_bulk_operation_t *bulk,
134
156
BSON_ASSERT (bulk );
135
157
BSON_ASSERT (selector );
136
158
137
- if (bulk -> result .error .domain ) {
138
- /* already failed e.g. a bad call to mongoc_bulk_operation_insert */
139
- RETURN (true);
140
- }
159
+ BULK_RETURN_IF_PRIOR_ERROR ;
141
160
142
161
if (bulk -> commands .len ) {
143
162
last = & _mongoc_array_index (
@@ -166,6 +185,10 @@ mongoc_bulk_operation_remove_one_with_opts (mongoc_bulk_operation_t *bulk,
166
185
bson_t opts_dup ;
167
186
bson_iter_t iter ;
168
187
188
+ ENTRY ;
189
+
190
+ BULK_RETURN_IF_PRIOR_ERROR ;
191
+
169
192
if (opts && bson_iter_init_find (& iter , opts , "limit" )) {
170
193
if ((!BSON_ITER_HOLDS_INT32 (& iter ) && !BSON_ITER_HOLDS_INT64 (& iter )) ||
171
194
!bson_iter_as_int64 (& iter )) {
@@ -174,7 +197,7 @@ mongoc_bulk_operation_remove_one_with_opts (mongoc_bulk_operation_t *bulk,
174
197
MONGOC_ERROR_COMMAND_INVALID_ARG ,
175
198
"%s expects the 'limit' option to be 1" ,
176
199
BSON_FUNC );
177
- return false;
200
+ RETURN ( false) ;
178
201
}
179
202
180
203
return _mongoc_bulk_operation_remove_with_opts (
@@ -190,7 +213,7 @@ mongoc_bulk_operation_remove_one_with_opts (mongoc_bulk_operation_t *bulk,
190
213
bulk , selector , & opts_dup , error );
191
214
bson_destroy (& opts_dup );
192
215
193
- return retval ;
216
+ RETURN ( retval ) ;
194
217
}
195
218
196
219
bool
@@ -203,6 +226,10 @@ mongoc_bulk_operation_remove_many_with_opts (mongoc_bulk_operation_t *bulk,
203
226
bson_t opts_dup ;
204
227
bson_iter_t iter ;
205
228
229
+ ENTRY ;
230
+
231
+ BULK_RETURN_IF_PRIOR_ERROR ;
232
+
206
233
if (opts && bson_iter_init_find (& iter , opts , "limit" )) {
207
234
if ((!BSON_ITER_HOLDS_INT32 (& iter ) && !BSON_ITER_HOLDS_INT64 (& iter )) ||
208
235
bson_iter_as_int64 (& iter )) {
@@ -211,11 +238,11 @@ mongoc_bulk_operation_remove_many_with_opts (mongoc_bulk_operation_t *bulk,
211
238
MONGOC_ERROR_COMMAND_INVALID_ARG ,
212
239
"%s expects the 'limit' option to be 0" ,
213
240
BSON_FUNC );
214
- return false;
241
+ RETURN ( false) ;
215
242
}
216
243
217
- return _mongoc_bulk_operation_remove_with_opts (
218
- bulk , selector , opts , error );
244
+ RETURN ( _mongoc_bulk_operation_remove_with_opts (
245
+ bulk , selector , opts , error )) ;
219
246
}
220
247
221
248
bson_init (& opts_dup );
@@ -227,7 +254,7 @@ mongoc_bulk_operation_remove_many_with_opts (mongoc_bulk_operation_t *bulk,
227
254
bulk , selector , & opts_dup , error );
228
255
bson_destroy (& opts_dup );
229
256
230
- return retval ;
257
+ RETURN ( retval ) ;
231
258
}
232
259
233
260
@@ -238,6 +265,10 @@ mongoc_bulk_operation_remove (mongoc_bulk_operation_t *bulk, /* IN */
238
265
bson_t opts ;
239
266
bson_error_t * error = & bulk -> result .error ;
240
267
268
+ ENTRY ;
269
+
270
+ BULK_EXIT_IF_PRIOR_ERROR ;
271
+
241
272
bson_init (& opts );
242
273
BSON_APPEND_INT32 (& opts , "limit" , 0 );
243
274
@@ -249,6 +280,8 @@ mongoc_bulk_operation_remove (mongoc_bulk_operation_t *bulk, /* IN */
249
280
if (error -> domain ) {
250
281
MONGOC_WARNING ("%s" , error -> message );
251
282
}
283
+
284
+ EXIT ;
252
285
}
253
286
254
287
@@ -259,6 +292,10 @@ mongoc_bulk_operation_remove_one (mongoc_bulk_operation_t *bulk, /* IN */
259
292
bson_t opts ;
260
293
bson_error_t * error = & bulk -> result .error ;
261
294
295
+ ENTRY ;
296
+
297
+ BULK_EXIT_IF_PRIOR_ERROR ;
298
+
262
299
bson_init (& opts );
263
300
BSON_APPEND_INT32 (& opts , "limit" , 1 );
264
301
@@ -269,6 +306,8 @@ mongoc_bulk_operation_remove_one (mongoc_bulk_operation_t *bulk, /* IN */
269
306
if (error -> domain ) {
270
307
MONGOC_WARNING ("%s" , error -> message );
271
308
}
309
+
310
+ EXIT ;
272
311
}
273
312
274
313
void
@@ -305,6 +344,13 @@ mongoc_bulk_operation_insert (mongoc_bulk_operation_t *bulk,
305
344
BSON_ASSERT (bulk );
306
345
BSON_ASSERT (document );
307
346
347
+ BULK_EXIT_IF_PRIOR_ERROR ;
348
+
349
+ if (!_mongoc_validate_new_document (document , & bulk -> result .error )) {
350
+ MONGOC_WARNING ("%s" , bulk -> result .error .message );
351
+ EXIT ;
352
+ }
353
+
308
354
if (bulk -> commands .len ) {
309
355
last = & _mongoc_array_index (
310
356
& bulk -> commands , mongoc_write_command_t , bulk -> commands .len - 1 );
@@ -322,7 +368,6 @@ mongoc_bulk_operation_insert (mongoc_bulk_operation_t *bulk,
322
368
bulk -> operation_id ,
323
369
!mongoc_write_concern_is_acknowledged (bulk -> write_concern ));
324
370
325
- _mongoc_validate_new_document (document , & bulk -> result .error );
326
371
_mongoc_array_append_val (& bulk -> commands , command );
327
372
328
373
EXIT ;
@@ -340,10 +385,7 @@ _mongoc_bulk_operation_replace_one_with_opts (mongoc_bulk_operation_t *bulk,
340
385
341
386
ENTRY ;
342
387
343
- if (bulk -> result .error .domain ) {
344
- /* already failed e.g. a bad call to mongoc_bulk_operation_insert */
345
- RETURN (true);
346
- }
388
+ BULK_RETURN_IF_PRIOR_ERROR ;
347
389
348
390
BSON_ASSERT (bulk );
349
391
BSON_ASSERT (selector );
@@ -378,6 +420,8 @@ mongoc_bulk_operation_replace_one (mongoc_bulk_operation_t *bulk,
378
420
bson_t opts ;
379
421
bson_error_t * error = & bulk -> result .error ;
380
422
423
+ ENTRY ;
424
+
381
425
bson_init (& opts );
382
426
BSON_APPEND_BOOL (& opts , "upsert" , upsert );
383
427
BSON_APPEND_BOOL (& opts , "multi" , false);
@@ -389,6 +433,8 @@ mongoc_bulk_operation_replace_one (mongoc_bulk_operation_t *bulk,
389
433
if (error -> domain ) {
390
434
MONGOC_WARNING ("%s" , error -> message );
391
435
}
436
+
437
+ EXIT ;
392
438
}
393
439
394
440
bool
@@ -444,11 +490,13 @@ _mongoc_bulk_operation_update_with_opts (mongoc_bulk_operation_t *bulk,
444
490
mongoc_write_command_t command = {0 };
445
491
mongoc_write_command_t * last ;
446
492
493
+ ENTRY ;
494
+
447
495
BSON_ASSERT (bulk );
448
496
BSON_ASSERT (selector );
449
497
BSON_ASSERT (document );
450
498
451
- ENTRY ;
499
+ BULK_RETURN_IF_PRIOR_ERROR ;
452
500
453
501
if (!_mongoc_validate_update (document , error )) {
454
502
RETURN (false);
@@ -481,18 +529,20 @@ mongoc_bulk_operation_update_one_with_opts (mongoc_bulk_operation_t *bulk,
481
529
bson_t opts_dup ;
482
530
bson_iter_t iter ;
483
531
532
+ ENTRY ;
533
+
484
534
if (opts && bson_iter_init_find (& iter , opts , "multi" )) {
485
535
if (!BSON_ITER_HOLDS_BOOL (& iter ) || bson_iter_bool (& iter )) {
486
536
bson_set_error (error ,
487
537
MONGOC_ERROR_COMMAND ,
488
538
MONGOC_ERROR_COMMAND_INVALID_ARG ,
489
539
"%s expects the 'multi' option to be false" ,
490
540
BSON_FUNC );
491
- return false;
541
+ RETURN ( false) ;
492
542
}
493
543
494
- return _mongoc_bulk_operation_update_with_opts (
495
- bulk , selector , document , opts , error );
544
+ RETURN ( _mongoc_bulk_operation_update_with_opts (
545
+ bulk , selector , document , opts , error )) ;
496
546
}
497
547
498
548
bson_init (& opts_dup );
@@ -504,7 +554,7 @@ mongoc_bulk_operation_update_one_with_opts (mongoc_bulk_operation_t *bulk,
504
554
bulk , selector , document , & opts_dup , error );
505
555
bson_destroy (& opts_dup );
506
556
507
- return retval ;
557
+ RETURN ( retval ) ;
508
558
}
509
559
510
560
bool
@@ -518,14 +568,16 @@ mongoc_bulk_operation_update_many_with_opts (mongoc_bulk_operation_t *bulk,
518
568
bson_t opts_dup ;
519
569
bson_iter_t iter ;
520
570
571
+ ENTRY ;
572
+
521
573
if (opts && bson_iter_init_find (& iter , opts , "multi" )) {
522
574
if (!BSON_ITER_HOLDS_BOOL (& iter ) || !bson_iter_bool (& iter )) {
523
575
bson_set_error (error ,
524
576
MONGOC_ERROR_COMMAND ,
525
577
MONGOC_ERROR_COMMAND_INVALID_ARG ,
526
578
"%s expects the 'multi' option to be true" ,
527
579
BSON_FUNC );
528
- return false;
580
+ RETURN ( false) ;
529
581
}
530
582
531
583
return _mongoc_bulk_operation_update_with_opts (
@@ -541,7 +593,7 @@ mongoc_bulk_operation_update_many_with_opts (mongoc_bulk_operation_t *bulk,
541
593
bulk , selector , document , & opts_dup , error );
542
594
bson_destroy (& opts_dup );
543
595
544
- return retval ;
596
+ RETURN ( retval ) ;
545
597
}
546
598
547
599
void
@@ -553,6 +605,10 @@ mongoc_bulk_operation_update (mongoc_bulk_operation_t *bulk,
553
605
bson_t opts ;
554
606
bson_error_t * error = & bulk -> result .error ;
555
607
608
+ ENTRY ;
609
+
610
+ BULK_EXIT_IF_PRIOR_ERROR ;
611
+
556
612
bson_init (& opts );
557
613
BSON_APPEND_BOOL (& opts , "upsert" , upsert );
558
614
BSON_APPEND_BOOL (& opts , "multi" , true);
@@ -565,6 +621,8 @@ mongoc_bulk_operation_update (mongoc_bulk_operation_t *bulk,
565
621
if (error -> domain ) {
566
622
MONGOC_WARNING ("%s" , error -> message );
567
623
}
624
+
625
+ EXIT ;
568
626
}
569
627
570
628
void
@@ -576,6 +634,10 @@ mongoc_bulk_operation_update_one (mongoc_bulk_operation_t *bulk,
576
634
bson_t opts ;
577
635
bson_error_t * error = & bulk -> result .error ;
578
636
637
+ ENTRY ;
638
+
639
+ BULK_EXIT_IF_PRIOR_ERROR ;
640
+
579
641
bson_init (& opts );
580
642
BSON_APPEND_BOOL (& opts , "upsert" , upsert );
581
643
BSON_APPEND_BOOL (& opts , "multi" , false);
@@ -588,6 +650,8 @@ mongoc_bulk_operation_update_one (mongoc_bulk_operation_t *bulk,
588
650
if (error -> domain ) {
589
651
MONGOC_WARNING ("%s" , error -> message );
590
652
}
653
+
654
+ EXIT ;
591
655
}
592
656
593
657
uint32_t
0 commit comments