Skip to content

Commit

Permalink
update render exception for run console
Browse files Browse the repository at this point in the history
  • Loading branch information
baselrabia committed Sep 22, 2022
1 parent a21e471 commit a82e4fc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/vendor/
/.idea
3 changes: 2 additions & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
class Application extends BaseApplication
{

const VERSION = '1.0.2';


/**
* Create a new Run application instance.
Expand Down Expand Up @@ -47,7 +49,6 @@ protected function registerBaseBindings()
$this->instance(self::class, $this);
$this->instance(Container::class, $this);

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

$this->singleton(PackageManifest::class, function () {
return new PackageManifest(
Expand Down
28 changes: 25 additions & 3 deletions src/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

namespace Run\Exceptions;

use Illuminate\Console\View\Components\BulletList;
use Illuminate\Console\View\Components\Error;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Throwable;
use Symfony\Component\Console\Exception\CommandNotFoundException;
use Symfony\Component\Console\Application as ConsoleApplication;

class Handler implements ExceptionHandler
{
Expand Down Expand Up @@ -50,14 +54,32 @@ public function render($request, Throwable $e)
/**
* Render an exception to the console.
*
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param \Throwable $e
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param \Throwable $e
* @return void
*
* @internal This method is not meant to be used or overwritten outside the framework.
*/
public function renderForConsole($output, Throwable $e)
{
// TODO: Implement renderForConsole() method.
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);
}

}

0 comments on commit a82e4fc

Please sign in to comment.