Skip to content

Commit 4f2ab27

Browse files
committed
UnsupportedException from WriteModelInterface::writeToBulk() instead of InvalidArgumentException
1 parent 47419ee commit 4f2ab27

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/BulkCompiler.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Tequila\MongoDB\Exception\InvalidArgumentException;
66
use Tequila\MongoDB\Exception\LogicException;
7+
use Tequila\MongoDB\Exception\RuntimeException;
8+
use Tequila\MongoDB\Exception\UnsupportedException;
79
use Tequila\MongoDB\OptionsResolver\BulkWrite\BulkWriteResolver;
810
use Tequila\MongoDB\Write\Model\WriteModelInterface;
911

@@ -68,10 +70,11 @@ public function compile(BulkWrite $bulkWrite, Server $server)
6870
foreach ($this->writeModels as $position => $writeModel) {
6971
try {
7072
$writeModel->writeToBulk($bulkWrite, $server);
71-
} catch(InvalidArgumentException $e) {
72-
throw new InvalidArgumentException(
73+
} catch(UnsupportedException $e) {
74+
throw new RuntimeException(
7375
sprintf(
74-
'Exception during parsing $writeModels[%d]: %s',
76+
'%s during applying $writeModels[%d] to BulkWrite: %s',
77+
UnsupportedException::class,
7578
$position,
7679
$e->getMessage()
7780
)

src/Write/Model/Traits/CheckCompatibilityTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
namespace Tequila\MongoDB\Write\Model\Traits;
44

55
use Tequila\MongoDB\Exception\InvalidArgumentException;
6+
use Tequila\MongoDB\Exception\UnsupportedException;
67
use Tequila\MongoDB\Server;
78

89
trait CheckCompatibilityTrait
910
{
1011
private function checkCompatibility(array $options, Server $server)
1112
{
1213
if (isset($options['collation']) && !$server->supportsCollation()) {
13-
throw new InvalidArgumentException(
14+
throw new UnsupportedException(
1415
'Option "collation" is not supported by the server.'
1516
);
1617
}

0 commit comments

Comments
 (0)