Skip to content

Commit 0b34ad8

Browse files
committed
Add details to the generic BulkWriteCommandException
1 parent ef9a2fc commit 0b34ad8

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/phongo_execute.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ bool phongo_execute_bulkwritecommand(zval* manager, php_phongo_bulkwritecommand_
440440
(void) spprintf(&message, 0, "Bulk write failed due to previous %s: %s", PHONGO_ZVAL_EXCEPTION_NAME(EG(exception)), error.message);
441441
zend_throw_exception(php_phongo_bulkwritecommandexception_ce, message, 0);
442442
efree(message);
443+
} else if (!has_top_level_error && bw_ret.res) {
444+
zend_throw_exception(php_phongo_bulkwritecommandexception_ce, "Bulk write failed with %d write concern errors and %d write errors", error.code, bw_ret.res->n_write_concern_errors, bw_ret.res->n_write_errors);
443445
} else {
444446
zend_throw_exception(php_phongo_bulkwritecommandexception_ce, has_top_level_error ? error.message : "Bulk write failed", error.code);
445447
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
MongoDB\Driver\BulkWriteCommandResult::isAcknowledged() with unacknowledged write concern
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_live(); ?>
6+
<?php skip_if_server_version('<', '8.0'); ?>
7+
<?php skip_if_not_clean(); ?>
8+
--FILE--
9+
<?php
10+
11+
require_once __DIR__ . "/../utils/basic.inc";
12+
13+
$manager = create_test_manager(URI);
14+
15+
$bulk = new MongoDB\Driver\BulkWriteCommand(['ordered' => false]);
16+
$bulk->insertOne(NS, ['_id' => 1]);
17+
$bulk->insertOne(NS, ['_id' => 1]);
18+
19+
echo throws(function() use ($result) {
20+
$manager->executeBulkWriteCommand($bulk);
21+
}, MongoDB\Driver\Exception\BulkWriteCommandException::class), "\n";
22+
23+
?>
24+
===DONE===
25+
<?php exit(0); ?>
26+
--EXPECT--
27+
bool(false)
28+
OK: Got MongoDB\Driver\Exception\BulkWriteCommandException
29+
Bulk write failed with 0 write concern errors and 1 write errors
30+
===DONE===

0 commit comments

Comments
 (0)