Skip to content

Commit

Permalink
fix(populate): Better TypeError handling on AutoMapper::map before in…
Browse files Browse the repository at this point in the history
…dexing
  • Loading branch information
welcoMattic committed Oct 21, 2024
1 parent 9122b37 commit 6d0c77f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Index/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Sylius\Component\Resource\Model\TranslatableInterface;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use TypeError;

final class Indexer implements IndexerInterface
{
Expand Down Expand Up @@ -192,7 +193,16 @@ private function indexDocumentable(OutputInterface $output, DocumentableInterfac
if (null !== $locale && $item instanceof TranslatableInterface) {
$item->setCurrentLocale($locale);
}
$dto = $this->autoMapper->map($item, $documentable->getTargetClass());

try {
$dto = $this->autoMapper->map($item, $documentable->getTargetClass());
} catch (TypeError $e) {
$id = method_exists($item, 'getId') ? $item->getId() : 'unknown';
$output->writeln(\sprintf('Error while mapping %s (id: %s): %s', $item::class, $id, $e->getMessage()));

continue;
}

// @phpstan-ignore-next-line
$indexer->scheduleIndex($newIndex, new Document((string) $dto->getId(), $dto));
}
Expand Down

0 comments on commit 6d0c77f

Please sign in to comment.