Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Fail queued job with a string message #45625

Merged
merged 3 commits into from Jan 13, 2023
Merged

[9.x] Fail queued job with a string message #45625

merged 3 commits into from Jan 13, 2023

Conversation

pascalbaljet
Copy link
Contributor

@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.

None yet

4 participants