Skip to content

[9.x] Improves command not found #1242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@
],
"require": {
"php": "^8.0.2",
"illuminate/auth": "^9.0",
"illuminate/broadcasting": "^9.0",
"illuminate/bus": "^9.0",
"illuminate/cache": "^9.0",
"illuminate/collections": "^9.0",
"illuminate/config": "^9.0",
"illuminate/console": "^9.0",
"illuminate/container": "^9.0",
"illuminate/contracts": "^9.0",
"illuminate/database": "^9.0",
"illuminate/encryption": "^9.0",
"illuminate/events": "^9.0",
"illuminate/filesystem": "^9.0",
"illuminate/hashing": "^9.0",
"illuminate/http": "^9.0",
"illuminate/macroable": "^9.0",
"illuminate/pagination": "^9.0",
"illuminate/pipeline": "^9.0",
"illuminate/queue": "^9.0",
"illuminate/support": "^9.0",
"illuminate/testing": "^9.0",
"illuminate/translation": "^9.0",
"illuminate/validation": "^9.0",
"illuminate/view": "^9.0",
"illuminate/log": "^9.0",
"illuminate/auth": "^9.21",
"illuminate/broadcasting": "^9.21",
"illuminate/bus": "^9.21",
"illuminate/cache": "^9.21",
"illuminate/collections": "^9.21",
"illuminate/config": "^9.21",
"illuminate/console": "^9.21",
"illuminate/container": "^9.21",
"illuminate/contracts": "^9.21",
"illuminate/database": "^9.21",
"illuminate/encryption": "^9.21",
"illuminate/events": "^9.21",
"illuminate/filesystem": "^9.21",
"illuminate/hashing": "^9.21",
"illuminate/http": "^9.21",
"illuminate/macroable": "^9.21",
"illuminate/pagination": "^9.21",
"illuminate/pipeline": "^9.21",
"illuminate/queue": "^9.21",
"illuminate/support": "^9.21",
"illuminate/testing": "^9.21",
"illuminate/translation": "^9.21",
"illuminate/validation": "^9.21",
"illuminate/view": "^9.21",
"illuminate/log": "^9.21",
"dragonmantank/cron-expression": "^3.1",
"nikic/fast-route": "^1.3",
"symfony/console": "^6.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function bootstrapRouter()
*/
public function version()
{
return 'Lumen (9.0.3) (Laravel Components ^9.0)';
return 'Lumen (9.0.3) (Laravel Components ^9.21)';
}

/**
Expand Down
20 changes: 20 additions & 0 deletions src/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Console\View\Components\BulletList;
use Illuminate\Console\View\Components\Error;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Database\Eloquent\ModelNotFoundException;
Expand All @@ -14,6 +16,7 @@
use Illuminate\Validation\ValidationException;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Exception\CommandNotFoundException;
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
Expand Down Expand Up @@ -199,6 +202,23 @@ protected function renderExceptionWithSymfony(Throwable $e, $debug)
*/
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