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 104239a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 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,15 @@ 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 104239a

Please sign in to comment.