Skip to content

Improve job serialization error message with job class name #56398

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/Illuminate/Queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Illuminate\Support\Collection;
use Illuminate\Support\InteractsWithTime;
use Illuminate\Support\Str;
use RuntimeException;
use Throwable;

abstract class Queue
{
Expand Down Expand Up @@ -167,9 +169,17 @@ protected function createObjectPayload($job, $queue)
'createdAt' => Carbon::now()->getTimestamp(),
]);

$command = $this->jobShouldBeEncrypted($job) && $this->container->bound(Encrypter::class)
? $this->container[Encrypter::class]->encrypt(serialize(clone $job))
: serialize(clone $job);
try {
$command = $this->jobShouldBeEncrypted($job) && $this->container->bound(Encrypter::class)
? $this->container[Encrypter::class]->encrypt(serialize(clone $job))
: serialize(clone $job);
} catch (Throwable $e) {
throw new RuntimeException(
sprintf('Failed to serialize job of type [%s]: %s', get_class($job), $e->getMessage()),
0,
$e
);
}

return array_merge($payload, [
'data' => array_merge($payload['data'], [
Expand Down Expand Up @@ -309,7 +319,6 @@ public static function createPayloadUsing($callback)
* Create the given payload using any registered payload hooks.
*
* @param string $queue
* @param array $payload
* @return array
*/
protected function withCreatePayloadHooks($queue, array $payload)
Expand Down Expand Up @@ -455,7 +464,6 @@ public function getContainer()
/**
* Set the IoC container instance.
*
* @param \Illuminate\Container\Container $container
* @return void
*/
public function setContainer(Container $container)
Expand Down