Skip to content

Commit

Permalink
Fix bug where uninitialized property within a job could break Ignition
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Dec 27, 2021
1 parent a394a1f commit d1dbc5e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/JobRecorder/JobRecorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
namespace Facade\Ignition\JobRecorder;

use DateTime;
use Error;
use Exception;
use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Queue\Job;
use Illuminate\Queue\CallQueuedClosure;
use Illuminate\Queue\Events\JobExceptionOccurred;
use Illuminate\Queue\Jobs\RedisJob;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use ReflectionClass;
use ReflectionProperty;
Expand Down Expand Up @@ -115,9 +117,13 @@ protected function resolveCommandProperties(object $command, int $maxChainDepth)
return in_array($property->name, $propertiesToIgnore);
})
->mapWithKeys(function (ReflectionProperty $property) use ($command) {
$property->setAccessible(true);
try{
$property->setAccessible(true);

return [$property->name => $property->getValue($command)];
return [$property->name => $property->getValue($command)];
}catch(Error $error) {
return [$property->name => 'uninitialized'];
}
});

if ($properties->has('chained')) {
Expand Down
2 changes: 2 additions & 0 deletions tests/stubs/jobs/QueueableJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class QueueableJob implements ShouldQueue
/** @var array */
private $property;

private string $uninitializedProperty;

public function __construct(
array $property,
?CarbonImmutable $retryUntilValue = null,
Expand Down

0 comments on commit d1dbc5e

Please sign in to comment.