1.0.0 Alpha Release #59

Merged
netkas merged 213 commits from v1.0.0_alpha into master 2023-01-29 23:27:58 +00:00
2 changed files with 20 additions and 5 deletions
Showing only changes of commit f41a3a6351 - Show all commits

View file

@ -11,6 +11,7 @@
use ncc\ncc; use ncc\ncc;
use ncc\Objects\CliHelpSection; use ncc\Objects\CliHelpSection;
use ncc\ThirdParty\Symfony\Process\ExecutableFinder; use ncc\ThirdParty\Symfony\Process\ExecutableFinder;
use Throwable;
class Console class Console
{ {
@ -317,16 +318,20 @@
* Prints out a detailed exception display (unfinished) * Prints out a detailed exception display (unfinished)
* *
* @param Exception $e * @param Exception $e
* @param bool $sub
* @return void * @return void
*/ */
private static function outExceptionDetails(Exception $e): void private static function outExceptionDetails(Throwable $e, bool $sub=false): void
{ {
if(!ncc::cliMode()) if(!ncc::cliMode())
return; return;
// Exception name without namespace
$trace_header = self::formatColor($e->getFile() . ':' . $e->getLine(), ConsoleColors::Magenta); $trace_header = self::formatColor($e->getFile() . ':' . $e->getLine(), ConsoleColors::Magenta);
$trace_error = self::formatColor('error: ', ConsoleColors::Red); $trace_error = self::formatColor( 'Error: ', ConsoleColors::Red);
self::out($trace_header . ' ' . $trace_error . $e->getMessage()); self::out($trace_header . ' ' . $trace_error . $e->getMessage());
self::out(sprintf('Exception: %s', get_class($e)));
self::out(sprintf('Error code: %s', $e->getCode())); self::out(sprintf('Error code: %s', $e->getCode()));
$trace = $e->getTrace(); $trace = $e->getTrace();
if(count($trace) > 1) if(count($trace) > 1)
@ -338,7 +343,16 @@
} }
} }
if(Main::getArgs() !== null) if($e->getPrevious() !== null)
{
// Check if previous is the same as the current
if($e->getPrevious()->getMessage() !== $e->getMessage())
{
self::outExceptionDetails($e->getPrevious(), true);
}
}
if(Main::getArgs() !== null && !$sub)
{ {
if(isset(Main::getArgs()['dbg-ex'])) if(isset(Main::getArgs()['dbg-ex']))
{ {

View file

@ -36,6 +36,7 @@
use ncc\ThirdParty\jelix\Version\Parser; use ncc\ThirdParty\jelix\Version\Parser;
use ncc\ThirdParty\Symfony\Filesystem\Filesystem; use ncc\ThirdParty\Symfony\Filesystem\Filesystem;
use PharData; use PharData;
use Throwable;
use ZipArchive; use ZipArchive;
/** /**
@ -290,7 +291,7 @@
* @param Exception $e * @param Exception $e
* @return array * @return array
*/ */
public static function exceptionToArray(Exception $e): array public static function exceptionToArray(Throwable $e): array
{ {
$exception = [ $exception = [
'message' => $e->getMessage(), 'message' => $e->getMessage(),
@ -303,7 +304,7 @@
if($e->getPrevious() !== null) if($e->getPrevious() !== null)
{ {
$exception['trace'] = self::exceptionToArray($e); $exception['previous'] = self::exceptionToArray($e->getPrevious());
} }
return $exception; return $exception;