Skip to content

Commit 89d5f0a

Browse files
authored
Preserve falsey concurrency exception parameters (#60822)
1 parent 31a10a8 commit 89d5f0a

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/Illuminate/Concurrency/ProcessDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function run(Closure|array $tasks, CarbonInterval|int|null $timeout = nul
6363

6464
if (! $result['successful']) {
6565
throw new $result['exception'](
66-
...(! empty(array_filter($result['parameters']))
66+
...(! empty(array_filter($result['parameters'], fn ($parameter) => ! is_null($parameter)))
6767
? $result['parameters']
6868
: [$result['message']])
6969
);

tests/Integration/Concurrency/ConcurrencyTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,31 @@ public function testRunHandlerProcessErrorWithCustomExceptionWithParam()
152152
]);
153153
}
154154

155+
#[DataProvider('falseyExceptionParameters')]
156+
public function testRunHandlerProcessErrorWithFalseyParam(int|bool|string $value)
157+
{
158+
try {
159+
Concurrency::run([
160+
fn () => throw new ExceptionWithFalseyParam($value),
161+
]);
162+
} catch (ExceptionWithFalseyParam $e) {
163+
$this->assertSame($value, $e->value);
164+
165+
return;
166+
}
167+
168+
$this->fail('The expected exception was not thrown.');
169+
}
170+
171+
public static function falseyExceptionParameters(): array
172+
{
173+
return [
174+
'zero' => [0],
175+
'false' => [false],
176+
'empty string' => [''],
177+
];
178+
}
179+
155180
public static function getConcurrencyDrivers(): array
156181
{
157182
return [
@@ -209,3 +234,11 @@ public function __construct(
209234
parent::__construct("API request to {$uri} failed with status $statusCode $reason");
210235
}
211236
}
237+
238+
class ExceptionWithFalseyParam extends Exception
239+
{
240+
public function __construct(public int|bool|string $value)
241+
{
242+
parent::__construct('Exception with falsey parameter');
243+
}
244+
}

0 commit comments

Comments
 (0)