Skip to content

Commit 13f4ced

Browse files
committed
Improve exception messages
1 parent af43b39 commit 13f4ced

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

src/Command/DeleteCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private function deleteIndex(string $indexName): void
7878
$path = sprintf('%s', $indexName);
7979
$this->client->request($path, Request::DELETE);
8080
} catch (ExceptionInterface $deleteOldIndexException) {
81-
throw new \RuntimeException(sprintf('Failed to delete index %s with message: %s', $indexName, $deleteOldIndexException->getMessage()), 0, $deleteOldIndexException);
81+
throw new \RuntimeException(sprintf('Failed to delete index "%s" with message: "%s"', $indexName, $deleteOldIndexException->getMessage()), 0, $deleteOldIndexException);
8282
}
8383
}
8484
}

src/Configuration/ConfigManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(array $sources)
3434
public function getIndexConfiguration(string $indexName): IndexConfigInterface
3535
{
3636
if (!$this->hasIndexConfiguration($indexName)) {
37-
throw new \InvalidArgumentException(sprintf('Index with name "%s" is not configured.', $indexName));
37+
throw new \InvalidArgumentException(sprintf('Index "%s" is not configured.', $indexName));
3838
}
3939

4040
return $this->indexes[$indexName];

src/DependencyInjection/FOSElasticaExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ private function buildCallback($indexCallback, $indexName)
319319
{
320320
if (is_array($indexCallback)) {
321321
if (!isset($indexCallback[0])) {
322-
throw new \InvalidArgumentException(sprintf('Invalid indexable_callback for index %s', $indexName));
322+
throw new \InvalidArgumentException(sprintf('Invalid indexable_callback for index "%s"', $indexName));
323323
}
324324

325325
$classOrServiceRef = $this->transformServiceReference($indexCallback[0]);
@@ -328,7 +328,7 @@ private function buildCallback($indexCallback, $indexName)
328328
}
329329

330330
if (!isset($indexCallback[1])) {
331-
throw new \InvalidArgumentException(sprintf('Invalid indexable_callback for index %s', $indexName));
331+
throw new \InvalidArgumentException(sprintf('Invalid indexable_callback for index "%s"', $indexName));
332332
}
333333

334334
return [$classOrServiceRef, $indexCallback[1]];
@@ -338,7 +338,7 @@ private function buildCallback($indexCallback, $indexName)
338338
return $this->transformServiceReference($indexCallback);
339339
}
340340

341-
throw new \InvalidArgumentException(sprintf('Invalid indexable_callback for index %s', $indexName));
341+
throw new \InvalidArgumentException(sprintf('Invalid indexable_callback for index "%s"', $indexName));
342342
}
343343

344344
private function transformServiceReference($classOrService)

src/Exception/AliasIsIndexException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ class AliasIsIndexException extends \Exception
1515
{
1616
public function __construct(string $indexName)
1717
{
18-
parent::__construct(sprintf('Expected %s to be an alias but it is an index.', $indexName));
18+
parent::__construct(sprintf('Expected "%s" to be an alias but it is an index.', $indexName));
1919
}
2020
}

src/Index/AliasProcessor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private function deleteIndex(Client $client, $indexName)
142142
$path = sprintf('%s', $indexName);
143143
$client->request($path, Request::DELETE);
144144
} catch (ExceptionInterface $deleteOldIndexException) {
145-
throw new \RuntimeException(sprintf('Failed to delete index %s with message: %s', $indexName, $deleteOldIndexException->getMessage()), 0, $deleteOldIndexException);
145+
throw new \RuntimeException(sprintf('Failed to delete index "%s" with message: "%s"', $indexName, $deleteOldIndexException->getMessage()), 0, $deleteOldIndexException);
146146
}
147147
}
148148

@@ -157,7 +157,7 @@ private function closeIndex(Client $client, $indexName)
157157
$path = sprintf('%s/_close', $indexName);
158158
$client->request($path, Request::POST);
159159
} catch (ExceptionInterface $e) {
160-
throw new \RuntimeException(sprintf('Failed to close index %s with message: %s', $indexName, $e->getMessage()), 0, $e);
160+
throw new \RuntimeException(sprintf('Failed to close index "%s" with message: "%s"', $indexName, $e->getMessage()), 0, $e);
161161
}
162162
}
163163

@@ -191,7 +191,7 @@ private function getAliasedIndex(Client $client, $aliasName)
191191
}
192192

193193
if (count($aliasedIndexes) > 1) {
194-
throw new \RuntimeException(sprintf('Alias %s is used for multiple indexes: [%s]. Make sure it\'s'.'either not used or is assigned to one index only', $aliasName, implode(', ', $aliasedIndexes)));
194+
throw new \RuntimeException(sprintf('Alias "%s" is used for multiple indexes: ["%s"]. Make sure it\'s'.'either not used or is assigned to one index only', $aliasName, implode('", "', $aliasedIndexes)));
195195
}
196196

197197
return array_shift($aliasedIndexes);

src/Manager/RepositoryManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getRepository(string $indexName): Repository
5353
}
5454

5555
if (!$this->hasRepository($indexName)) {
56-
throw new \RuntimeException(sprintf('No repository configured for %s', $indexName));
56+
throw new \RuntimeException(sprintf('No repository is configured for index "%s"', $indexName));
5757
}
5858

5959
$repository = $this->createRepository($indexName);
@@ -82,7 +82,7 @@ protected function getRepositoryName(string $indexName): string
8282
private function createRepository(string $indexName)
8383
{
8484
if (!class_exists($repositoryName = $this->getRepositoryName($indexName))) {
85-
throw new \RuntimeException(sprintf('%s repository for %s does not exist', $repositoryName, $indexName));
85+
throw new \RuntimeException(sprintf('%s repository for index "%s" does not exist', $repositoryName, $indexName));
8686
}
8787

8888
return new $repositoryName($this->indexes[$indexName]['finder']);

0 commit comments

Comments
 (0)