Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/phongo_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ bool phongo_execute_bulk_write(zval* manager, const char* namespace, php_phongo_
/* A BulkWriteException is always thrown if mongoc_bulk_operation_execute()
* fails to ensure that the write result is accessible. If the error does
* not originate from the server (e.g. socket error), throw the appropriate
* exception first. It will be included in BulkWriteException's message and
* will also be accessible via Exception::getPrevious(). */
* exception first. It will be thrown directly */
if (!success) {
if (error.domain != MONGOC_ERROR_SERVER && error.domain != MONGOC_ERROR_WRITE_CONCERN) {
phongo_throw_exception_from_bson_error_t_and_reply(&error, &reply);
Expand All @@ -311,11 +310,7 @@ bool phongo_execute_bulk_write(zval* manager, const char* namespace, php_phongo_
}

if (EG(exception)) {
char* message;

(void) spprintf(&message, 0, "Bulk write failed due to previous %s: %s", PHONGO_ZVAL_EXCEPTION_NAME(EG(exception)), error.message);
zend_throw_exception(php_phongo_bulkwriteexception_ce, message, 0);
efree(message);
zend_throw_exception(phongo_exception_from_phongo_domain(error.domain), error.message, error.code);
} else {
zend_throw_exception(php_phongo_bulkwriteexception_ce, error.message, error.code);
}
Expand Down
39 changes: 4 additions & 35 deletions tests/manager/manager-executeBulkWrite_error-005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,14 @@ $bulk->insert(['x' => 1]);
$bulk->update(['x' => 1], ['$set' => ['y' => 1]]);
$bulk->delete(['x' => 1]);

try {
echo throws(function() use ($server, $bulk) {
$server->executeBulkWrite(NS, $bulk);
} catch (MongoDB\Driver\Exception\BulkWriteException $e) {
printf("%s(%d): %s\n", get_class($e), $e->getCode(), $e->getMessage());
$prev = $e->getPrevious();
printf("%s(%d): %s\n", get_class($prev), $prev->getCode(), $prev->getMessage());
var_dump($e->getWriteResult());
}
}, MongoDB\Driver\Exception\ConnectionTimeoutException::class), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
MongoDB\Driver\Exception\BulkWriteException(0): Bulk write failed due to previous MongoDB\Driver\Exception\ConnectionTimeoutException: Failed to send "delete" command with database "%s": Failed to read 4 bytes: socket error or timeout
MongoDB\Driver\Exception\ConnectionTimeoutException(%d): Failed to send "delete" command with database "%s": Failed to read 4 bytes: socket error or timeout
object(MongoDB\Driver\WriteResult)#%d (%d) {
["nInserted"]=>
int(1)
["nMatched"]=>
int(1)
["nModified"]=>
int(1)
["nRemoved"]=>
int(0)
["nUpserted"]=>
int(0)
["upsertedIds"]=>
array(0) {
}
["writeErrors"]=>
array(0) {
}
["writeConcernError"]=>
NULL
["writeConcern"]=>
object(MongoDB\Driver\WriteConcern)#%d (%d) {
}
["errorReplies"]=>
array(0) {
}
}
OK: Got MongoDB\Driver\Exception\ConnectionTimeoutException
Failed to send "delete" command with database "%s": Failed to read 4 bytes: socket error or timeout
Comment on lines +35 to +36
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current result is:

Deprecated: Creation of dynamic property MongoDB\Driver\Exception\RuntimeException::$writeResult is deprecated in /Users/jerome/Develop/mongo-php-driver/tests/manager/manager-executeBulkWrite_error-005.php on line 20
ALMOST: Got MongoDB\Driver\Exception\RuntimeException - expected MongoDB\Driver\Exception\ConnectionTimeoutException
Failed to send "delete" command with database "phongo": Failed to read 4 bytes: socket error or timeout

I need to fix the "dynamic property" issue and the exception class.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got the correct exception class by using phongo_throw_exception_from_bson_error_t_and_reply(&error, &reply).

Deprecated: Creation of dynamic property MongoDB\Driver\Exception\ConnectionTimeoutException::$writeResult is deprecated in /Users/jerome/Develop/mongo-php-driver/tests/manager/manager-executeBulkWrite_error-005.php on line 20
OK: Got MongoDB\Driver\Exception\ConnectionTimeoutException
Failed to send "delete" command with database "phongo": Failed to read 4 bytes: socket error or timeout

Now I need to figure where the dynamic property comes from.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test successful after adding ConnectionTimeoutException::$writeResult.

===DONE===
Loading