From d0d8f66ababf94617ca8e452cc9f2312708ca78c Mon Sep 17 00:00:00 2001 From: David Badura Date: Thu, 14 Dec 2023 10:12:35 +0100 Subject: [PATCH] replace dump output with own implementation --- src/Console/Command/ProjectionStatusCommand.php | 6 +++--- src/Console/OutputStyle.php | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Console/Command/ProjectionStatusCommand.php b/src/Console/Command/ProjectionStatusCommand.php index b74e12d32..2746f85ff 100644 --- a/src/Console/Command/ProjectionStatusCommand.php +++ b/src/Console/Command/ProjectionStatusCommand.php @@ -12,9 +12,9 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Throwable; use function array_map; -use function dump; #[AsCommand( 'event-sourcing:projection:status', @@ -91,8 +91,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $errorObject = $projection->errorObject(); - if ($errorObject) { - dump($errorObject); + if ($errorObject instanceof Throwable) { + $io->throwable($errorObject); } return 0; diff --git a/src/Console/OutputStyle.php b/src/Console/OutputStyle.php index 6964f1fba..c2f908386 100644 --- a/src/Console/OutputStyle.php +++ b/src/Console/OutputStyle.php @@ -9,6 +9,9 @@ use Patchlevel\EventSourcing\Serializer\Encoder\Encoder; use Patchlevel\EventSourcing\Serializer\EventSerializer; use Symfony\Component\Console\Style\SymfonyStyle; +use Throwable; + +use function sprintf; final class OutputStyle extends SymfonyStyle { @@ -37,4 +40,17 @@ public function message(EventSerializer $serializer, Message $message): void $this->block($data->payload); } + + public function throwable(Throwable $error): void + { + $number = 1; + + do { + $this->error(sprintf('%d) %s', $number, $error->getMessage())); + $this->block($error->getTraceAsString()); + + $number++; + $error = $error->getPrevious(); + } while ($error !== null); + } }