Skip to content

Commit 12356e2

Browse files
committed
Use UnsupportedException instead of CommandException
1 parent 5d84469 commit 12356e2

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/Exception/UnsupportedException.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ public static function collationNotSupported()
3939
return new static('Collations are not supported by the server executing this operation');
4040
}
4141

42+
/**
43+
* Thrown when the commitQuorum option for createIndexes is not supported
44+
* by a server.
45+
*
46+
* @return self
47+
*/
48+
public static function commitQuorumNotSupported()
49+
{
50+
return new static('The "commitQuorum" option is not supported by the server executing this operation');
51+
}
52+
4253
/**
4354
* Thrown when explain is not supported by a server.
4455
*

src/Operation/CreateIndexes.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
namespace MongoDB\Operation;
1919

2020
use MongoDB\Driver\Command;
21-
use MongoDB\Driver\Exception\CommandException;
2221
use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
2322
use MongoDB\Driver\Server;
2423
use MongoDB\Driver\Session;
@@ -219,7 +218,7 @@ private function executeCommand(Server $server)
219218
/* Drivers MUST manually raise an error if this option is specified
220219
* when creating an index on a pre 4.4 server. */
221220
if (! server_supports_feature($server, self::$wireVersionForCommitQuorum)) {
222-
throw new CommandException('Invalid field specified for createIndexes command: commitQuorum', 2);
221+
throw UnsupportedException::commitQuorumNotSupported();
223222
}
224223

225224
$cmd['commitQuorum'] = $this->options['commitQuorum'];

tests/Operation/CreateIndexesFunctionalTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace MongoDB\Tests\Operation;
44

55
use InvalidArgumentException;
6-
use MongoDB\Driver\Exception\CommandException;
76
use MongoDB\Driver\Exception\RuntimeException;
87
use MongoDB\Driver\Server;
8+
use MongoDB\Exception\UnsupportedException;
99
use MongoDB\Model\IndexInfo;
1010
use MongoDB\Operation\CreateIndexes;
1111
use MongoDB\Operation\ListIndexes;
@@ -213,8 +213,8 @@ public function testCommitQuorumUnsupported()
213213
['commitQuorum' => 'majority']
214214
);
215215

216-
$this->expectException(CommandException::class);
217-
$this->expectExceptionMessage('Invalid field specified for createIndexes command: commitQuorum');
216+
$this->expectException(UnsupportedException::class);
217+
$this->expectExceptionMessage('The "commitQuorum" option is not supported by the server executing this operation');
218218

219219
$operation->execute($this->getPrimaryServer());
220220
}

0 commit comments

Comments
 (0)