Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions src/MongoDB/Cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,12 @@ static void php_phongo_cursor_iterator_move_forward(zend_object_iterator* iter T
php_phongo_bson_to_zval_ex(bson_get_data(doc), doc->len, &cursor->visitor_data);
} else {
bson_error_t error = { 0 };
const bson_t* doc = NULL;

if (mongoc_cursor_error(cursor->cursor, &error)) {
if (mongoc_cursor_error_document(cursor->cursor, &error, &doc)) {
/* Intentionally not destroying the cursor as it will happen
* naturally now that there are no more results */
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC);
phongo_throw_exception_from_bson_error_t_and_reply(&error, doc TSRMLS_CC);
}
}

Expand Down
44 changes: 44 additions & 0 deletions tests/cursor/bug1419-001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
--TEST--
PHPC-1419: error labels from getMore are not exposed
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_not_libmongoc_crypto(); ?>
<?php skip_if_no_failcommand_failpoint(); ?>
<?php skip_if_server_version('<', '4.1.11'); ?>
<?php skip_if_not_clean(); ?>
--FILE--
<?php
require_once __DIR__ . "/../utils/basic.inc";

$manager = new MongoDB\Driver\Manager(URI);

// Select a specific server for future operations to avoid mongos switching in sharded clusters
$server = $manager->selectServer(new \MongoDB\Driver\ReadPreference('primary'));

$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert(['_id' => 1]);
$bulk->insert(['_id' => 2]);
$bulk->insert(['_id' => 3]);
$manager->executeBulkWrite(NS, $bulk);

$cursor = $server->executeQuery(NS, new \MongoDB\Driver\Query([], ['batchSize' => 1]));
$iterator = new IteratorIterator($cursor);

configureTargetedFailPoint(
$server,
'failCommand',
[ 'times' => 1] ,
[ 'errorCode' => 280, 'failCommands' => ['getMore'] ]
Copy link
Member

Choose a reason for hiding this comment

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

Is the error code sufficient for the fail point to also apply the label? I see the label defined as a category in error_codes.yml but didn't realize that would work with failCommand. I suppose it makes sense, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, the label is automatically added based on the error code. IIRC, you can't define error labels through the failCommand fail point.

);

try {
$iterator->next();
} catch (\MongoDB\Driver\Exception\ServerException $e) {
var_dump($e->hasErrorLabel('NonResumableChangeStreamError'));
}

?>
===DONE===
--EXPECT--
bool(true)
===DONE===