Skip to content

Commit

Permalink
Improve error message for NotFoundException
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Aug 30, 2021
1 parent a4b9d7a commit 9ba1ac3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Exception/NotFoundException.php
Expand Up @@ -17,8 +17,15 @@ final class NotFoundException extends Exception implements NotFoundExceptionInte
public function __construct(string $id, array $buildStack = [])
{
$this->id = $id;
$buildStackMessage = $buildStack ? ' while building ' . implode(' -> ', array_keys($buildStack)) : '';
parent::__construct(sprintf('No definition or class found for %s%s.', $id, $buildStackMessage));

$message = $id;
if ($buildStack !== []) {
$buildStack = array_keys($buildStack);
$last = end($buildStack);
$message = sprintf('%s while building %s', $last, implode(' -> ', $buildStack));
}

parent::__construct(sprintf('No definition or class found for %s.', $message));
}

public function getId(): string
Expand Down

0 comments on commit 9ba1ac3

Please sign in to comment.