Skip to content

Commit 1ad6d75

Browse files
committed
PHPC-1090: Clean up switch statements for exception class selection
1 parent 04dc9f1 commit 1ad6d75

File tree

3 files changed

+11
-50
lines changed

3 files changed

+11
-50
lines changed

php_phongo.c

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -144,57 +144,16 @@ zend_class_entry* phongo_exception_from_mongoc_domain(uint32_t /* mongoc_error_d
144144
return php_phongo_connectiontimeoutexception_ce;
145145
case MONGOC_ERROR_CLIENT_AUTHENTICATE:
146146
return php_phongo_authenticationexception_ce;
147-
148147
case MONGOC_ERROR_COMMAND_INVALID_ARG:
149148
return php_phongo_invalidargumentexception_ce;
150-
151-
case MONGOC_ERROR_STREAM_INVALID_TYPE:
152-
case MONGOC_ERROR_STREAM_INVALID_STATE:
153-
case MONGOC_ERROR_STREAM_NAME_RESOLUTION:
154-
case MONGOC_ERROR_STREAM_CONNECT:
155-
case MONGOC_ERROR_STREAM_NOT_ESTABLISHED:
156-
return php_phongo_connectionexception_ce;
157-
case MONGOC_ERROR_CLIENT_NOT_READY:
158-
case MONGOC_ERROR_CLIENT_TOO_BIG:
159-
case MONGOC_ERROR_CLIENT_TOO_SMALL:
160-
case MONGOC_ERROR_CLIENT_GETNONCE:
161-
case MONGOC_ERROR_CLIENT_NO_ACCEPTABLE_PEER:
162-
case MONGOC_ERROR_CLIENT_IN_EXHAUST:
163-
case MONGOC_ERROR_PROTOCOL_INVALID_REPLY:
164-
case MONGOC_ERROR_PROTOCOL_BAD_WIRE_VERSION:
165-
case MONGOC_ERROR_CURSOR_INVALID_CURSOR:
166-
/*case MONGOC_ERROR_PROTOCOL_ERROR:*/
167-
case MONGOC_ERROR_BSON_INVALID:
168-
case MONGOC_ERROR_MATCHER_INVALID:
169-
case MONGOC_ERROR_NAMESPACE_INVALID:
170-
case MONGOC_ERROR_GRIDFS_INVALID_FILENAME:
171-
return php_phongo_runtimeexception_ce;
172-
case MONGOC_ERROR_QUERY_FAILURE:
173-
case MONGOC_ERROR_QUERY_COMMAND_NOT_FOUND:
174-
case MONGOC_ERROR_QUERY_NOT_TAILABLE:
175-
case MONGOC_ERROR_COLLECTION_INSERT_FAILED:
176-
return php_phongo_serverexception_ce;
177149
}
178150
switch (domain) {
151+
case MONGOC_ERROR_COMMAND:
152+
// TODO: return php_phongo_commandexception_ce after PHPC-1089 is merged
179153
case MONGOC_ERROR_SERVER:
180154
return php_phongo_serverexception_ce;
181-
case MONGOC_ERROR_CLIENT:
182155
case MONGOC_ERROR_STREAM:
183-
case MONGOC_ERROR_PROTOCOL:
184-
case MONGOC_ERROR_CURSOR:
185-
case MONGOC_ERROR_QUERY:
186-
case MONGOC_ERROR_INSERT:
187-
case MONGOC_ERROR_SASL:
188-
case MONGOC_ERROR_BSON:
189-
case MONGOC_ERROR_MATCHER:
190-
case MONGOC_ERROR_NAMESPACE:
191-
case MONGOC_ERROR_COMMAND:
192-
case MONGOC_ERROR_COLLECTION:
193-
case MONGOC_ERROR_GRIDFS:
194-
/* FIXME: We don't have the Exceptions mocked yet.. */
195-
#if 0
196-
return phongo_ce_mongo_connection_exception;
197-
#endif
156+
return php_phongo_connectionexception_ce;
198157
default:
199158
return php_phongo_runtimeexception_ce;
200159
}
@@ -703,7 +662,7 @@ bool phongo_execute_bulk_write(mongoc_client_t* client, const char* namespace, p
703662
/* The Write failed */
704663
if (!success) {
705664
if ((error.domain == MONGOC_ERROR_COMMAND && error.code != MONGOC_ERROR_COMMAND_INVALID_ARG) ||
706-
error.domain == MONGOC_ERROR_WRITE_CONCERN) {
665+
error.domain == MONGOC_ERROR_SERVER || error.domain == MONGOC_ERROR_WRITE_CONCERN) {
707666
phongo_throw_exception(PHONGO_ERROR_WRITE_FAILED TSRMLS_CC, "%s", error.message);
708667
phongo_add_exception_prop(ZEND_STRL("writeResult"), return_value TSRMLS_CC);
709668
} else {
@@ -2372,6 +2331,7 @@ void phongo_manager_init(php_phongo_manager_t* manager, const char* uri_string,
23722331
#endif
23732332

23742333
manager->client = php_phongo_make_mongo_client(uri TSRMLS_CC);
2334+
mongoc_client_set_error_api(manager->client, MONGOC_ERROR_API_VERSION_2);
23752335

23762336
if (!manager->client) {
23772337
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to create Manager from URI: '%s'", uri_string);

tests/apm/overview.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ object(MongoDB\Driver\Monitoring\CommandFailedEvent)#%d (%d) {
7070
["durationMicros"]=>
7171
int(%d)
7272
["error"]=>
73-
object(MongoDB\Driver\Exception\RuntimeException)#%d (%d) {
73+
object(MongoDB\Driver\Exception\ServerException)#%d (%d) {
7474
["message":protected]=>
7575
string(12) "ns not found"
7676
["string":"Exception":private]=>

tests/standalone/write-error-001.phpt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ $hannes_id = $bulk->insert($hannes);
1717
$w = 2;
1818
$wtimeout = 1000;
1919
$writeConcern = new \MongoDB\Driver\WriteConcern($w, $wtimeout);
20-
throws(function() use($bulk, $writeConcern, $manager) {
20+
echo throws(function() use($bulk, $writeConcern, $manager) {
2121
$result = $manager->executeBulkWrite(NS, $bulk, $writeConcern);
22-
}, "MongoDB\Driver\Exception\ConnectionException");
22+
}, "MongoDB\Driver\Exception\BulkWriteException"), "\n";
2323

2424
?>
2525
===DONE===
2626
<?php exit(0); ?>
27-
--EXPECTF--
28-
OK: Got MongoDB\Driver\Exception\ConnectionException
27+
--EXPECT--
28+
OK: Got MongoDB\Driver\Exception\BulkWriteException
29+
cannot use 'w' > 1 when a host is not replicated
2930
===DONE===

0 commit comments

Comments
 (0)