Skip to content

Commit 845edf6

Browse files
committed
Merge branch 'v1.5'
2 parents 29fafa4 + 95d2d5c commit 845edf6

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

php_phongo.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static void phongo_exception_add_error_labels(bson_t* reply TSRMLS_DC)
230230
}
231231
}
232232

233-
void phongo_throw_exception_from_bson_error_and_reply_t(bson_error_t* error, bson_t* reply TSRMLS_DC)
233+
void phongo_throw_exception_from_bson_error_t_and_reply(bson_error_t* error, const bson_t* reply TSRMLS_DC)
234234
{
235235
/* Server errors (other than ExceededTimeLimit) and write concern errors
236236
* may use CommandException and report the result document for the
@@ -802,7 +802,7 @@ bool phongo_execute_bulk_write(mongoc_client_t* client, const char* namespace, p
802802
* returned and an exception is thrown. */
803803
bool phongo_cursor_advance_and_check_for_error(mongoc_cursor_t* cursor TSRMLS_DC) /* {{{ */
804804
{
805-
const bson_t* doc;
805+
const bson_t* doc = NULL;
806806

807807
if (!mongoc_cursor_next(cursor, &doc)) {
808808
bson_error_t error = { 0 };
@@ -813,8 +813,8 @@ bool phongo_cursor_advance_and_check_for_error(mongoc_cursor_t* cursor TSRMLS_DC
813813
}
814814

815815
/* Could simply be no docs, which is not an error */
816-
if (mongoc_cursor_error(cursor, &error)) {
817-
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC);
816+
if (mongoc_cursor_error_document(cursor, &error, &doc)) {
817+
phongo_throw_exception_from_bson_error_t_and_reply(&error, doc TSRMLS_CC);
818818
return false;
819819
}
820820
}
@@ -1031,7 +1031,7 @@ bool phongo_execute_command(mongoc_client_t* client, php_phongo_command_type_t t
10311031
free_reply = true;
10321032

10331033
if (!result) {
1034-
phongo_throw_exception_from_bson_error_and_reply_t(&error, &reply TSRMLS_CC);
1034+
phongo_throw_exception_from_bson_error_t_and_reply(&error, &reply TSRMLS_CC);
10351035
goto cleanup;
10361036
}
10371037

php_phongo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void phongo_throw_exception(php_phongo_error_domain_t domain TSRMLS
111111
#endif /* PHP_VERSION_ID < 70000 */
112112
;
113113
void phongo_throw_exception_from_bson_error_t(bson_error_t* error TSRMLS_DC);
114-
void phongo_throw_exception_from_bson_error_and_reply_t(bson_error_t* error, bson_t* reply TSRMLS_DC);
114+
void phongo_throw_exception_from_bson_error_t_and_reply(bson_error_t* error, const bson_t* reply TSRMLS_DC);
115115

116116
/* This enum is used for processing options in phongo_execute_parse_options and
117117
* selecting a libmongoc function to use in phongo_execute_command. The values

src/MongoDB/Session.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ static PHP_METHOD(Session, commitTransaction)
350350
}
351351

352352
if (!mongoc_client_session_commit_transaction(intern->client_session, &reply, &error)) {
353-
phongo_throw_exception_from_bson_error_and_reply_t(&error, &reply TSRMLS_CC);
353+
phongo_throw_exception_from_bson_error_t_and_reply(&error, &reply TSRMLS_CC);
354354
bson_destroy(&reply);
355355
}
356356
} /* }}} */
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::executeQuery() exposes error document via CommandException
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_live(); ?>
6+
<?php skip_if_server_version('<', '3.2'); ?>
7+
--FILE--
8+
<?php
9+
require_once __DIR__ . "/../utils/basic.inc";
10+
11+
$manager = new MongoDB\Driver\Manager(URI);
12+
$query = new MongoDB\Driver\Query(['$foo' => 1]);
13+
14+
try {
15+
$manager->executeQuery(NS, $query);
16+
} catch (\MongoDB\Driver\Exception\CommandException $e) {
17+
printf("%s(%d): %s\n", get_class($e), $e->getCode(), $e->getMessage());
18+
$doc = $e->getResultDocument();
19+
var_dump($doc->errmsg === $e->getMessage());
20+
var_dump($doc->code === $e->getCode());
21+
}
22+
23+
?>
24+
===DONE===
25+
<?php exit(0); ?>
26+
--EXPECT--
27+
MongoDB\Driver\Exception\CommandException(2): unknown top level operator: $foo
28+
bool(true)
29+
bool(true)
30+
===DONE===

0 commit comments

Comments
 (0)