Skip to content

Commit

Permalink
upd error format
Browse files Browse the repository at this point in the history
  • Loading branch information
phphleb committed Feb 13, 2024
1 parent 85d418b commit e69a4fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions HlebBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function __construct(?string $publicPath = null, array $config = [], ?Log

// The current version of the framework.
// Текущая версия фреймворка.
\defined('HLEB_CORE_VERSION') or \define('HLEB_CORE_VERSION', '2.0.5');
\defined('HLEB_CORE_VERSION') or \define('HLEB_CORE_VERSION', '2.0.6');

$this->logger = $logger;

Expand Down Expand Up @@ -691,7 +691,7 @@ protected function scriptErrorHandling(\Throwable $t): void
$this->getLogger()->error($t);

if (DynamicParams::isDebug()) {
$message = ' ERROR: ' . $t;
$message = PHP_EOL . '<pre>ERROR: ' . $t . '</pre>' . PHP_EOL;
} else {
$message = '';
}
Expand Down
25 changes: 19 additions & 6 deletions Init/ErrorLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static function execute(int $errno, string $errstr, string $errfile = nul
case E_CORE_ERROR:
self::outputNotice();
$log->critical($errstr, $params);
\async_exit($debug ? (SystemSettings::isCli() ? '' : $errstr) : '', 500);
\async_exit($debug ? (SystemSettings::isCli() ? '' : self::format($errstr)) : '', 500);
break;
case E_ERROR:
case E_USER_ERROR:
Expand All @@ -116,32 +116,31 @@ public static function execute(int $errno, string $errstr, string $errfile = nul
case E_RECOVERABLE_ERROR:
self::outputNotice();
$log->error($errstr, $params);
\async_exit($debug ? (SystemSettings::isCli() ? '' : $errstr) : '', 500);
\async_exit($debug ? (SystemSettings::isCli() ? '' : self::format($errstr)) : '', 500);
break;
case E_USER_WARNING:
case E_WARNING:
case E_CORE_WARNING:
case E_COMPILE_WARNING:
self::outputNotice();
$log->warning($errstr, $params);
$debug and print PHP_EOL . "Warning: $errstr in $errfile:$errline" . PHP_EOL;
$debug and print self::format( "Warning: $errstr in $errfile:$errline");
break;
case E_USER_NOTICE:
case E_NOTICE:
case E_STRICT:
case E_DEPRECATED:
case E_USER_DEPRECATED:
$log->notice($errstr, $params);
$debug and self::$notices[] = PHP_EOL . "Notice: $errstr in $errfile:$errline" . PHP_EOL;
$debug and self::$notices[] = self::format("Notice: $errstr in $errfile:$errline");
break;
default:
self::outputNotice();
$log->error($errstr, $params);
\async_exit($debug ? (SystemSettings::isCli() ? '' : $errstr) : '', 500);
\async_exit($debug ? (SystemSettings::isCli() ? '' : self::format($errstr)) : '', 500);
break;
}
self::$config and SystemSettings::setData(self::$config);

} catch (\Throwable $t) {
\error_log((string)$t);
self::$config = [];
Expand Down Expand Up @@ -308,4 +307,18 @@ private static function outputNotice(): void
self::$notices = [];
}
}

/**
* Formatting the error output.
*
* Форматирование выводимой ошибки.
*/
private static function format(string $message): string
{
if (SystemSettings::isCli()) {
return $message . PHP_EOL . PHP_EOL;
}

return PHP_EOL . "<pre>$message</pre>" . PHP_EOL;
}
}

0 comments on commit e69a4fe

Please sign in to comment.