From 7026e5fd48dff599a4e3f112168be407682308ff Mon Sep 17 00:00:00 2001 From: David Badura Date: Mon, 29 Jan 2024 11:06:18 +0100 Subject: [PATCH] use array as trace in projection error --- src/Console/Command/ProjectionStatusCommand.php | 6 +++++- src/Projection/Projection/Store/ErrorContext.php | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Console/Command/ProjectionStatusCommand.php b/src/Console/Command/ProjectionStatusCommand.php index 4f2796e1b..7db9b076e 100644 --- a/src/Console/Command/ProjectionStatusCommand.php +++ b/src/Console/Command/ProjectionStatusCommand.php @@ -16,6 +16,7 @@ use function array_map; use function is_array; +use function sprintf; /** @psalm-import-type Context from ErrorContext */ #[AsCommand( @@ -106,6 +107,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int private function displayError(OutputStyle $io, array $context): void { $io->error($context['message']); - $io->block($context['trace']); + + foreach ($context['trace'] as $trace) { + $io->writeln(sprintf('%s: %s', $trace['file'] ?? '#unknown', $trace['line'] ?? '#unknown')); + } } } diff --git a/src/Projection/Projection/Store/ErrorContext.php b/src/Projection/Projection/Store/ErrorContext.php index af18b3655..d4bb13962 100644 --- a/src/Projection/Projection/Store/ErrorContext.php +++ b/src/Projection/Projection/Store/ErrorContext.php @@ -6,7 +6,10 @@ use Throwable; -/** @psalm-type Context = array{message: string, code: int|string, file: string, line: int, trace: string} */ +/** + * @psalm-type Trace = array{file?: string, line?: int, function?: string, class?: string, type?: string, args?: array} + * @psalm-type Context = array{message: string, code: int|string, file: string, line: int, trace: list} + */ final class ErrorContext { /** @return list */ @@ -15,7 +18,7 @@ public static function fromThrowable(Throwable $error): array $errors = []; do { - $errors[] = self::transform($error); + $errors[] = self::transformThrowable($error); $error = $error->getPrevious(); } while ($error); @@ -23,14 +26,14 @@ public static function fromThrowable(Throwable $error): array } /** @return Context */ - private static function transform(Throwable $error): array + private static function transformThrowable(Throwable $error): array { return [ 'message' => $error->getMessage(), 'code' => $error->getCode(), 'file' => $error->getFile(), 'line' => $error->getLine(), - 'trace' => $error->getTraceAsString(), + 'trace' => $error->getTrace(), ]; } }