diff --git a/src/MongoDB/Cursor.c b/src/MongoDB/Cursor.c index 9d697af21..686649073 100644 --- a/src/MongoDB/Cursor.c +++ b/src/MongoDB/Cursor.c @@ -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); } } diff --git a/tests/cursor/bug1419-001.phpt b/tests/cursor/bug1419-001.phpt new file mode 100644 index 000000000..5c0c0753b --- /dev/null +++ b/tests/cursor/bug1419-001.phpt @@ -0,0 +1,44 @@ +--TEST-- +PHPC-1419: error labels from getMore are not exposed +--SKIPIF-- + + + + + +--FILE-- +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'] ] +); + +try { + $iterator->next(); +} catch (\MongoDB\Driver\Exception\ServerException $e) { + var_dump($e->hasErrorLabel('NonResumableChangeStreamError')); +} + +?> +===DONE=== +--EXPECT-- +bool(true) +===DONE===