Skip to content

Commit

Permalink
Catch exception when unserializing
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Aug 15, 2022
1 parent 72c6e91 commit 9463319
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/TagBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Setono\TagBag\Tag\RenderedTag;
use Setono\TagBag\Tag\TagInterface;
use Throwable;
use TypeError;

final class TagBag implements TagBagInterface, LoggerAwareInterface
{
Expand Down Expand Up @@ -195,7 +196,11 @@ public function restore(): void

$this->tags = [];
if (null !== $data) {
$this->tags = $this->unserialize($data);
try {
$this->tags = $this->unserialize($data);
} catch (TypeError $e) {
$this->logger->error(sprintf('Exception thrown when trying to unserialize data. Error was: %s. Data was: %s', $e->getMessage(), $data));
}
}
}

Expand Down Expand Up @@ -242,6 +247,8 @@ private function findTagByFingerprint(string $fingerprint): ?array
/**
* @psalm-suppress MixedInferredReturnType
*
* @throws TypeError if the unserialized data doesn't unserialize to instances of RenderedTag
*
* @return array<string, list<RenderedTag>>
*/
private function unserialize(string $data): array
Expand Down

0 comments on commit 9463319

Please sign in to comment.