stackkit / laravel-google-cloud-tasks-queue

Use Google Cloud Tasks as the queue driver for Laravel
MIT License
69 stars 36 forks source link

Exception during Job handling will never log an error #153

Closed beliven-daniele-sarnari closed 3 months ago

beliven-daniele-sarnari commented 3 months ago

Hello,

The following implementation https://github.com/stackkit/laravel-google-cloud-tasks-queue/blob/52452fc2648eb2ce9413afedc7770812270e2bef/src/TaskHandler.php#L44C9-L44C15 will never throw an Exception, correctly. The down side of this is that a Stack trace or simply a log of the error will never be printed. Following this pattern, any error logging method (as Sentry or Mezmo) will never catch the error.

public function handle(?string $task = null): void
    {
        $task = IncomingTask::fromJson($task ?: request()->getContent());

        event(new TaskIncoming($task));

        if ($task->isInvalid()) {
            abort(422, 'Invalid task payload');
        }

        if (! CloudTasksApi::exists($task->fullyQualifiedTaskName())) {
            abort(404);
        }

        $config = config('queue.connections.'.$task->connection());

        $this->config = is_array($config) ? $config : [];

        // We want to catch any errors so we have more fine-grained control over
        // how tasks are retried. Cloud Tasks will retry the task if a 5xx status
        // is returned. Because we manually manage retries by releaseing jobs,
        // we never want to return a 5xx status as that will result in duplicate
        // job attempts.
        rescue(fn () => $this->run($task), report: false);
    }

Solution: just ignore report field or set it as true

marickvantuil commented 3 months ago

Thanks! I think I got report confused with actually throwing the exception 🙃, but I've released a v4.2.1 with a fix!