Skip to content

[10.x] Nullable failed method #9445

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

Merged
merged 1 commit into from
Mar 4, 2024
Merged

[10.x] Nullable failed method #9445

merged 1 commit into from
Mar 4, 2024

Conversation

timacdonald
Copy link
Member

@timacdonald timacdonald commented Mar 3, 2024

The exception may be null if you call the fail method without passing a string or exception, as documented.

Screen Shot 2024-03-04 at 9 02 43 am

So having this nullable in the docs seems more sensible, as the two documented version do not currently work together. If this were typed with Throwable an exception would be thrown when the queue worker attempts to call the job's failed method.

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class TestJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function handle(): void
    {
        $this->fail();
    }

    public function failed($e)
    {
        dd($e); // null
    }
}

@taylorotwell taylorotwell merged commit 215d89e into laravel:10.x Mar 4, 2024
@timacdonald timacdonald deleted the failed branch March 4, 2024 21:44
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.

2 participants