Skip to content

Conversation

@pascalbaljet
Copy link
Member

@pascalbaljet pascalbaljet commented Jan 12, 2023

A shortcut so you can fail a job with a string message instead of manually instantiating an Exception.

class MyJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable;

    public function handle()
    {
        // Before:
        $this->fail(new \Exception('Whoops!'));

        // After:
        $this->fail('Whoops!');
    }
}

@pascalbaljet pascalbaljet changed the title [9.x] Fail queued job with a string [9.x] Fail queued job with a string message Jan 12, 2023
@WendellAdriel
Copy link
Contributor

This seems nice but at least IMO it would be better to throw a custom exception instead of a generic one

@SjorsO
Copy link
Contributor

SjorsO commented Jan 13, 2023

The report() and throw_if() helpers can also receive a string message (see #35890). The only difference is they can also receive the FQN of an exception class, like this:

throw_if($hasError, LogicException::class);

Supporting $this->fail(LogicException::class) is probably a good idea to keep things consistent.

@taylorotwell taylorotwell merged commit 4ca6ad0 into laravel:9.x Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants