Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kayintveen's avatar

Queueable job failed() must be an instance of App\Jobs\Exception issue

Hi all,

I have a queueable job which might fail sometimes. When it fails i need a few records to be updated in the initial model that is used.

in the job class i added a failed method

public function failed(Exception $exception)
    {
        $this->feed_connection->scheduled = 0;
        $this->feed_connection->running = 0;
        $this->feed_connection->failed = 1;
        $this->feed_connection->last_failed_date = Carbon::now();
        $this->feed_connection->save();
    }

But when i use this i get several errors like:

local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 1 passed to App\Jobs\processXmlConnection::failed() must be an instance of App\Jobs\Exception, instance of Symfony\Component\Debug\Exception\FatalThrowableError given

and

local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 1 passed to App\Jobs\processXmlConnection::failed() must be an instance of App\Jobs\Exception, instance of Nathanmac\Utilities\Parser\Exceptions\ParserException given

Probably something missing here but i tried everything. Anybody got a clue?

0 likes
3 replies
astierler's avatar

Try changing your failed() function to..

public function failed($exception) {
    // ...
}

If looking at the Queue\Jobs\Job class, you'll see they don't enforce Exception here..

    /**
     * Process an exception that caused the job to fail.
     *
     * @param  \Exception  $e
     * @return void
     */
    public function failed($e)
    { // ...
    }
2 likes
kayintveen's avatar

This has been magically solved. i just removed the exception since im not using it at all. I just need to know if a process is running or not.

thanks

    public function failed()
    {
        $this->feed_connection->scheduled = 0;
        $this->feed_connection->running = 0;
        $this->feed_connection->failed = 1;
        $this->feed_connection->last_failed_date = Carbon::now();
        $this->feed_connection->save();
        event(new FinishedProductImport($this->feed_connection, 'failed'));
    }
stef25's avatar

In the job class, did you add the "use Exception" statement?

Please or to participate in this conversation.