Skip to content

Commit d7ee886

Browse files
committed
IBX-9846: Added dedicated exception
1 parent 9d17bd9 commit d7ee886

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

src/contracts/Search/Embedding/EmbeddingProviderResolverInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010

1111
interface EmbeddingProviderResolverInterface
1212
{
13+
/**
14+
* @throws \Ibexa\Contracts\Core\Search\Embedding\EmbeddingResolverNotFoundException
15+
*/
1316
public function resolve(): EmbeddingProviderInterface;
1417
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
namespace Ibexa\Contracts\Core\Search\Embedding;
8+
9+
use RuntimeException;
10+
11+
final class EmbeddingResolverNotFoundException extends RuntimeException
12+
{
13+
public function __construct(
14+
string $embeddingProvider
15+
) {
16+
$message = sprintf('No embedding provider registered for identifier "%s".', $embeddingProvider);
17+
18+
parent::__construct($message);
19+
}
20+
}

src/lib/Search/Embedding/EmbeddingProviderResolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Ibexa\Contracts\Core\Search\Embedding\EmbeddingProviderInterface;
1313
use Ibexa\Contracts\Core\Search\Embedding\EmbeddingProviderRegistryInterface;
1414
use Ibexa\Contracts\Core\Search\Embedding\EmbeddingProviderResolverInterface;
15-
use RuntimeException;
15+
use Ibexa\Contracts\Core\Search\Embedding\EmbeddingResolverNotFoundException;
1616

1717
final class EmbeddingProviderResolver implements EmbeddingProviderResolverInterface
1818
{
@@ -33,8 +33,8 @@ public function resolve(): EmbeddingProviderInterface
3333
$defaultEmbeddingProvider = $this->embeddingConfiguration->getDefaultEmbeddingProvider();
3434

3535
if (!$this->registry->hasEmbeddingProvider($defaultEmbeddingProvider)) {
36-
throw new RuntimeException(
37-
sprintf('No embedding provider registered for identifier "%s".', $defaultEmbeddingProvider)
36+
throw new EmbeddingResolverNotFoundException(
37+
$defaultEmbeddingProvider
3838
);
3939
}
4040

tests/lib/Search/Embedding/EmbeddingProviderResolverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
use Ibexa\Contracts\Core\Search\Embedding\EmbeddingConfigurationInterface;
1212
use Ibexa\Contracts\Core\Search\Embedding\EmbeddingProviderInterface;
1313
use Ibexa\Contracts\Core\Search\Embedding\EmbeddingProviderRegistryInterface;
14+
use Ibexa\Contracts\Core\Search\Embedding\EmbeddingResolverNotFoundException;
1415
use Ibexa\Core\Search\Embedding\EmbeddingProviderResolver;
1516
use PHPUnit\Framework\TestCase;
16-
use RuntimeException;
1717

1818
final class EmbeddingProviderResolverTest extends TestCase
1919
{
@@ -72,7 +72,7 @@ public function testResolveThrowsWhenProviderMissing(): void
7272
->with($embeddingProviderIdentifier)
7373
->willReturn(false);
7474

75-
$this->expectException(RuntimeException::class);
75+
$this->expectException(EmbeddingResolverNotFoundException::class);
7676
$this->expectExceptionMessage(
7777
sprintf('No embedding provider registered for identifier "%s".', $embeddingProviderIdentifier)
7878
);

0 commit comments

Comments
 (0)