Skip to content

Commit

Permalink
Improves command not found (#43323)
Browse files Browse the repository at this point in the history
Co-Authored-By: Slava Razum <[email protected]>

Co-authored-by: Slava Razum <[email protected]>
  • Loading branch information
nunomaduro and slavarazum authored Jul 20, 2022
1 parent 8a0db35 commit bc76c95
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Illuminate/Foundation/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Console\View\Components\BulletList;
use Illuminate\Console\View\Components\Error;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandlerContract;
use Illuminate\Contracts\Foundation\ExceptionRenderer;
Expand All @@ -30,6 +32,7 @@
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Exception\CommandNotFoundException;
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
use Symfony\Component\HttpFoundation\RedirectResponse as SymfonyRedirectResponse;
Expand Down Expand Up @@ -718,6 +721,23 @@ protected function convertExceptionToArray(Throwable $e)
*/
public function renderForConsole($output, Throwable $e)
{
if ($e instanceof CommandNotFoundException) {
$message = str($e->getMessage())->explode('.')->first();

if (! empty($alternatives = $e->getAlternatives())) {
$message .= '. Did you mean one of these?';

with(new Error($output))->render($message);
with(new BulletList($output))->render($e->getAlternatives());

$output->writeln('');
} else {
with(new Error($output))->render($message);
}

return;
}

(new ConsoleApplication)->renderThrowable($e, $output);
}

Expand Down

0 comments on commit bc76c95

Please sign in to comment.