Skip to content

Commit 6d0c77f

Browse files
committed
fix(populate): Better TypeError handling on AutoMapper::map before indexing
1 parent 9122b37 commit 6d0c77f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Index/Indexer.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Sylius\Component\Resource\Model\TranslatableInterface;
2929
use Symfony\Component\Console\Output\NullOutput;
3030
use Symfony\Component\Console\Output\OutputInterface;
31+
use TypeError;
3132

3233
final class Indexer implements IndexerInterface
3334
{
@@ -192,7 +193,16 @@ private function indexDocumentable(OutputInterface $output, DocumentableInterfac
192193
if (null !== $locale && $item instanceof TranslatableInterface) {
193194
$item->setCurrentLocale($locale);
194195
}
195-
$dto = $this->autoMapper->map($item, $documentable->getTargetClass());
196+
197+
try {
198+
$dto = $this->autoMapper->map($item, $documentable->getTargetClass());
199+
} catch (TypeError $e) {
200+
$id = method_exists($item, 'getId') ? $item->getId() : 'unknown';
201+
$output->writeln(\sprintf('Error while mapping %s (id: %s): %s', $item::class, $id, $e->getMessage()));
202+
203+
continue;
204+
}
205+
196206
// @phpstan-ignore-next-line
197207
$indexer->scheduleIndex($newIndex, new Document((string) $dto->getId(), $dto));
198208
}

0 commit comments

Comments
 (0)