Skip to content

Commit cfbf2cc

Browse files
committed
Improve exception message
1 parent 50560d2 commit cfbf2cc

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/Scout/ScoutEngine.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Database\Eloquent\SoftDeletes;
1010
use Illuminate\Support\Collection;
1111
use Illuminate\Support\LazyCollection;
12+
use InvalidArgumentException;
1213
use Laravel\Scout\Builder;
1314
use Laravel\Scout\Engines\Engine;
1415
use Laravel\Scout\Searchable;
@@ -439,7 +440,7 @@ public function createIndex($name, array $options = []): void
439440

440441
$definition = $this->indexDefinitions[$name] ?? self::DEFAULT_DEFINITION;
441442
if (! isset($definition['mappings'])) {
442-
throw new LogicException(sprintf('The search index definition for collection "scout.mongodb.index-definition.%s" must contain a "mappings" key. Find documentation at https://www.mongodb.com/docs/atlas/atlas-search/create-index/', $name));
443+
throw new InvalidArgumentException(sprintf('Invalid search index definition for collection "%s", the "mappings" key is required. Find documentation at https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/#search-index-definition-syntax', $name));
443444
}
444445

445446
// Ensure the collection exists before creating the search index

tests/Scout/ScoutEngineTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testCreateIndexInvalidDefinition(): void
4040
$engine = new ScoutEngine($database, false, ['collection_invalid' => ['foo' => 'bar']]);
4141

4242
$this->expectException(LogicException::class);
43-
$this->expectExceptionMessage('The search index definition for collection "scout.mongodb.index-definition.collection_invalid" must contain a "mappings" key');
43+
$this->expectExceptionMessage('Invalid search index definition for collection "collection_invalid", the "mappings" key is required.');
4444
$engine->createIndex('collection_invalid');
4545
}
4646

0 commit comments

Comments
 (0)