Skip to content

Commit

Permalink
use array as trace in projection error
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Jan 29, 2024
1 parent 7899776 commit 7026e5f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/Console/Command/ProjectionStatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use function array_map;
use function is_array;
use function sprintf;

/** @psalm-import-type Context from ErrorContext */
#[AsCommand(
Expand Down Expand Up @@ -106,6 +107,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
private function displayError(OutputStyle $io, array $context): void

Check failure on line 107 in src/Console/Command/ProjectionStatusCommand.php

View workflow job for this annotation

GitHub Actions / Static Analysis by PHPStan (locked, 8.3, ubuntu-latest)

Method Patchlevel\EventSourcing\Console\Command\ProjectionStatusCommand::displayError() has parameter $context with no value type specified in iterable type array.
{
$io->error($context['message']);
$io->block($context['trace']);

foreach ($context['trace'] as $trace) {
$io->writeln(sprintf('%s: %s', $trace['file'] ?? '#unknown', $trace['line'] ?? '#unknown'));
}
}
}
11 changes: 7 additions & 4 deletions src/Projection/Projection/Store/ErrorContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<Trace>}
*/
final class ErrorContext
{
/** @return list<Context> */
Expand All @@ -15,22 +18,22 @@ public static function fromThrowable(Throwable $error): array
$errors = [];

do {
$errors[] = self::transform($error);
$errors[] = self::transformThrowable($error);
$error = $error->getPrevious();
} while ($error);

return $errors;
}

/** @return Context */
private static function transform(Throwable $error): array
private static function transformThrowable(Throwable $error): array

Check failure on line 29 in src/Projection/Projection/Store/ErrorContext.php

View workflow job for this annotation

GitHub Actions / Static Analysis by PHPStan (locked, 8.3, ubuntu-latest)

Method Patchlevel\EventSourcing\Projection\Projection\Store\ErrorContext::transformThrowable() return type has no value type specified in iterable type array.
{
return [
'message' => $error->getMessage(),
'code' => $error->getCode(),
'file' => $error->getFile(),
'line' => $error->getLine(),
'trace' => $error->getTraceAsString(),
'trace' => $error->getTrace(),
];
}
}

0 comments on commit 7026e5f

Please sign in to comment.