Skip to content

Commit

Permalink
[8.x] Update CallQueuedClosure to catch Throwable/Error (#36159)
Browse files Browse the repository at this point in the history
* Update CallQueuedClosure to catch Throwable/Error

- Laravel Version: 8.26.1
- PHP Version: 8.0.0

### Description:
Queued closures that throw an Error will throw again when handled by CallQueuedClosure@failed, as its currently type-hinted for Exceptions only.

### Steps To Reproduce:
```php
Bus::chain([
    function () {
        SomeClassThatDoesntExist::throw();
    }
])->dispatch();
```

The above will first throw `Error Class "SomeClassThatDoesntExist" not found`. The queue will attempt to handle it and throw again: `TypeError
Illuminate\Queue\CallQueuedClosure::failed(): Argument #1 ($e) must be of type Exception, Error given, called in /var/task/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php on line 261`

* style: styleci fixes

* Update CallQueuedClosure.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
ryzr and taylorotwell authored Feb 7, 2021
1 parent 7fd4510 commit 2ecc0b4
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Illuminate/Queue/CallQueuedClosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Illuminate\Queue;

use Closure;
use Exception;
use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Container\Container;
Expand Down Expand Up @@ -87,10 +86,10 @@ public function onFailure($callback)
/**
* Handle a job failure.
*
* @param \Exception $e
* @param \Throwable $e
* @return void
*/
public function failed(Exception $e)
public function failed($e)
{
foreach ($this->failureCallbacks as $callback) {
call_user_func($callback instanceof SerializableClosure ? $callback->getClosure() : $callback, $e);
Expand Down

0 comments on commit 2ecc0b4

Please sign in to comment.