Skip to content

Commit dead06a

Browse files
derickrjmikola
authored andcommitted
PHPC-357: "invalid namespace" exception should report the namespace
1 parent c4d0342 commit dead06a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

php_phongo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ bool phongo_execute_write(mongoc_client_t *client, const char *namespace, mongoc
597597
php_phongo_writeresult_t *writeresult;
598598

599599
if (!phongo_split_namespace(namespace, &dbname, &collname)) {
600-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s", "Invalid namespace provided");
600+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s: %s", "Invalid namespace provided", namespace);
601601
return false;
602602
}
603603

@@ -664,7 +664,7 @@ int phongo_execute_query(mongoc_client_t *client, const char *namespace, const p
664664
mongoc_collection_t *collection;
665665

666666
if (!phongo_split_namespace(namespace, &dbname, &collname)) {
667-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s", "Invalid namespace provided");
667+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s: %s", "Invalid namespace provided", namespace);
668668
return false;
669669
}
670670
collection = mongoc_client_get_collection(client, dbname, collname);

tests/manager/bug0357.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
PHPC-357: The exception for "invalid namespace" does not list the broken name
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
$m = new MongoDB\Driver\Manager("mongodb://localhost:44444");
9+
10+
$c = new MongoDB\Driver\Query( [] );
11+
12+
try {
13+
$m->executeQuery( 'demo', $c );
14+
echo "Expected exception not thrown\n";
15+
}
16+
catch ( InvalidArgumentException $e )
17+
{
18+
echo $e->getMessage(), "\n";
19+
}
20+
?>
21+
--EXPECTF--
22+
Invalid namespace provided: demo

0 commit comments

Comments
 (0)