Skip to content

Commit 74d5ef4

Browse files
Fix undefined variable $e in withModelFailover when providers array is empty (#221)
* Fix undefined variable $e when failover providers array is empty * Use string user_id columns to support UUID and ULID primary keys * Revert "Use string user_id columns to support UUID and ULID primary keys" This reverts commit d82498f. * Update Promptable.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent c42a101 commit 74d5ef4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Promptable.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Laravel\Ai\Responses\StreamableAgentResponse;
2525
use Laravel\Ai\Streaming\Events\StreamEvent;
2626
use ReflectionClass;
27+
use RuntimeException;
2728

2829
trait Promptable
2930
{
@@ -141,6 +142,8 @@ private function withModelFailover(Closure $callback, Lab|array|string|null $pro
141142
{
142143
$providers = $this->getProvidersAndModels($provider, $model);
143144

145+
$lastException = null;
146+
144147
foreach ($providers as $provider => $model) {
145148
$provider = Ai::textProviderFor($this, $provider);
146149

@@ -149,13 +152,15 @@ private function withModelFailover(Closure $callback, Lab|array|string|null $pro
149152
try {
150153
return $callback($provider, $model);
151154
} catch (FailoverableException $e) {
155+
$lastException = $e;
156+
152157
event(new AgentFailedOver($this, $provider, $model, $e));
153158

154159
continue;
155160
}
156161
}
157162

158-
throw $e;
163+
throw $lastException ?? new RuntimeException('No AI providers were configured.');
159164
}
160165

161166
/**

0 commit comments

Comments
 (0)