Skip to content

Conversation

zackAJ
Copy link
Contributor

@zackAJ zackAJ commented Jan 28, 2025

Description

This PR gives better error handling when calling the uniqueVia() method in case the wrong value is returned from the function.

example:

    public function uniqueVia()
    {
        return 'a string value';
    }

This will throw an exception in InteractsWithUniqueJobs (#54000)

    /**
     * Determine the cache store used by the unique job to acquire locks.
     *
     * @param  mixed  $job
     * @return string|null
     */
    protected function getUniqueJobCacheStore($job): ?string
    {
        return method_exists($job, 'uniqueVia')
-            ? $job->uniqueVia()->getName()
+            ? $job->uniqueVia()->getName() //throws here
            : config('cache.default');
    }

The following ambiguous error is thrown

current-error

This PR provides better error handling

new-error

Let me know if this requires a test.

@zackAJ zackAJ changed the title [11.x] Fix better error handling for uniqueVia() when wrong type is returned [11.x] Fix error handling for uniqueVia() when wrong type is returned Jan 28, 2025
@taylorotwell
Copy link
Member

To be honest we never actually document returning a string from this method?

https://laravel.com/docs/11.x/queues#unique-job-locks

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