Skip to content

Commit

Permalink
Prettier cli exceptions in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
freost committed Oct 28, 2024
1 parent 365291c commit 2961241
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/mako/error/handlers/cli/DevelopmentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace mako\error\handlers\cli;

use ErrorException;
use mako\cli\output\helpers\Alert;
use mako\cli\output\Output;
use mako\error\handlers\HandlerInterface;
use Throwable;
Expand Down Expand Up @@ -74,20 +75,25 @@ protected function determineExceptionType(Throwable $exception): string
*/
public function handle(Throwable $exception): mixed
{
$type = $this->escape($this->determineExceptionType($exception));
$alert = (new Alert($this->output))->render(

Check failure on line 78 in src/mako/error/handlers/cli/DevelopmentHandler.php

View workflow job for this annotation

GitHub Actions / Static analysis (8.3)

Method mako\cli\output\helpers\Alert::render() invoked with 3 parameters, 1-2 required.
"<bold>{$this->escape($this->determineExceptionType($exception))}</bold> [ {$exception->getCode()} ]",
Alert::DANGER,
Output::ERROR
);

$message = $this->escape($exception->getMessage());
$info = "<red><bold>{$this->escape($exception->getMessage())}</bold></red>";

if (!empty($exception->getFile())) {
$message .= PHP_EOL
$info .= PHP_EOL
. PHP_EOL
. "Error location: {$this->escape($exception->getFile())}"
. " on line {$this->escape($exception->getLine())}";
. "The error occured in <bold>{$this->escape($exception->getFile())}</bold>"
. " on line <bold>{$exception->getLine()}</bold>"
. PHP_EOL;
}

$trace = $this->escape($exception->getTraceAsString());

$this->output->errorLn("<bg_red><white>{$type}: {$message}" . PHP_EOL . PHP_EOL . $trace . PHP_EOL . '</white></bg_red>');
$this->output->errorLn($alert . PHP_EOL . $info . PHP_EOL . $trace);

return false;
}
Expand Down

0 comments on commit 2961241

Please sign in to comment.