Skip to content

Commit a82e4fc

Browse files
committed
update render exception for run console
1 parent a21e471 commit a82e4fc

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/vendor/
2+
/.idea

src/Application.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
class Application extends BaseApplication
1414
{
1515

16+
const VERSION = '1.0.2';
17+
1618

1719
/**
1820
* Create a new Run application instance.
@@ -47,7 +49,6 @@ protected function registerBaseBindings()
4749
$this->instance(self::class, $this);
4850
$this->instance(Container::class, $this);
4951

50-
$this->instance('files', new \Illuminate\Filesystem\Filesystem);
5152

5253
$this->singleton(PackageManifest::class, function () {
5354
return new PackageManifest(

src/Exceptions/Handler.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
namespace Run\Exceptions;
44

5+
use Illuminate\Console\View\Components\BulletList;
6+
use Illuminate\Console\View\Components\Error;
57
use Illuminate\Contracts\Debug\ExceptionHandler;
68
use Throwable;
9+
use Symfony\Component\Console\Exception\CommandNotFoundException;
10+
use Symfony\Component\Console\Application as ConsoleApplication;
711

812
class Handler implements ExceptionHandler
913
{
@@ -50,14 +54,32 @@ public function render($request, Throwable $e)
5054
/**
5155
* Render an exception to the console.
5256
*
53-
* @param \Symfony\Component\Console\Output\OutputInterface $output
54-
* @param \Throwable $e
57+
* @param \Symfony\Component\Console\Output\OutputInterface $output
58+
* @param \Throwable $e
5559
* @return void
5660
*
5761
* @internal This method is not meant to be used or overwritten outside the framework.
5862
*/
5963
public function renderForConsole($output, Throwable $e)
6064
{
61-
// TODO: Implement renderForConsole() method.
65+
if ($e instanceof CommandNotFoundException) {
66+
$message = str($e->getMessage())->explode('.')->first();
67+
68+
if (! empty($alternatives = $e->getAlternatives())) {
69+
$message .= '. Did you mean one of these?';
70+
71+
with(new Error($output))->render($message);
72+
with(new BulletList($output))->render($e->getAlternatives());
73+
74+
$output->writeln('');
75+
} else {
76+
with(new Error($output))->render($message);
77+
}
78+
79+
return;
80+
}
81+
82+
(new ConsoleApplication)->renderThrowable($e, $output);
6283
}
84+
6385
}

0 commit comments

Comments
 (0)