From 2961241a82d1d1b1deb2f044d98a45539a14e945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederic=20G=2E=20=C3=98stby?= Date: Mon, 28 Oct 2024 22:08:24 +0100 Subject: [PATCH] Prettier cli exceptions in dev mode --- .../error/handlers/cli/DevelopmentHandler.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/mako/error/handlers/cli/DevelopmentHandler.php b/src/mako/error/handlers/cli/DevelopmentHandler.php index 6aa7cf207..8743b9ae9 100644 --- a/src/mako/error/handlers/cli/DevelopmentHandler.php +++ b/src/mako/error/handlers/cli/DevelopmentHandler.php @@ -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; @@ -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( + "{$this->escape($this->determineExceptionType($exception))} [ {$exception->getCode()} ]", + Alert::DANGER, + Output::ERROR + ); - $message = $this->escape($exception->getMessage()); + $info = "{$this->escape($exception->getMessage())}"; 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 {$this->escape($exception->getFile())}" + . " on line {$exception->getLine()}" + . PHP_EOL; } $trace = $this->escape($exception->getTraceAsString()); - $this->output->errorLn("{$type}: {$message}" . PHP_EOL . PHP_EOL . $trace . PHP_EOL . ''); + $this->output->errorLn($alert . PHP_EOL . $info . PHP_EOL . $trace); return false; }