Skip to content

Commit f447c5f

Browse files
author
Valentin Nazarov
authored
Fix retryable exceptions class list in RetryOptions (#96)
* Fix retryable exceptions class list in RetryOptions * Allow use of Throwable::class in non-retryable exceptions list
1 parent f53f162 commit f447c5f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Common/RetryOptions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,13 @@ public function withMaximumAttempts(int $attempts): self
193193
/**
194194
* @psalm-suppress ImpureMethodCall
195195
*
196-
* @param mixed $exceptions
196+
* @param ExceptionsList $exceptions
197197
* @return $this
198198
*/
199199
#[Pure]
200200
public function withNonRetryableExceptions(array $exceptions): self
201201
{
202-
assert(Assert::valuesInstanceOf($exceptions, \Throwable::class));
202+
assert(Assert::valuesSubclassOfOrSameClass($exceptions, \Throwable::class));
203203

204204
$self = clone $this;
205205
$self->nonRetryableExceptions = $exceptions;

src/Internal/Assert.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ public static function valuesInstanceOf(array $values, string $of): bool
4646
}
4747

4848
/**
49-
* @param array<object> $values
49+
* @param array<class-string> $values
50+
* @param class-string $of
51+
* @return bool
52+
*/
53+
public static function valuesSubclassOfOrSameClass(array $values, string $of): bool
54+
{
55+
return self::all($values, fn ($v) => is_a($v, $of, true));
56+
}
57+
58+
/**
59+
* @param array<mixed> $values
5060
* @param callable $filter
5161
* @return bool
5262
*/

0 commit comments

Comments
 (0)