From 3f24d514194d4098c587dff218cec3a0d843e9d8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 3 Feb 2012 17:46:31 +0100 Subject: [PATCH] Repack plain exceptions into a SystemException to benefit from its improvements. --- wcfsetup/install/files/lib/system/WCF.class.php | 4 ++-- .../lib/system/exception/LoggedException.class.php | 7 +++++-- .../lib/system/exception/SystemException.class.php | 14 ++++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index a5dd3b07f2..249deb0bb5 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -238,8 +238,8 @@ class WCF { exit; } - print $e; - exit; + // repack Exception + self::handleException(new exception\SystemException($e->getMessage(), $e->getCode(), '', $e)); } /** diff --git a/wcfsetup/install/files/lib/system/exception/LoggedException.class.php b/wcfsetup/install/files/lib/system/exception/LoggedException.class.php index b04573424c..5e119ce080 100644 --- a/wcfsetup/install/files/lib/system/exception/LoggedException.class.php +++ b/wcfsetup/install/files/lib/system/exception/LoggedException.class.php @@ -14,6 +14,7 @@ use wcf\system\WCF; * @category Community Framework */ class LoggedException extends \Exception { + /** * Surpresses the original error message. * @@ -24,7 +25,8 @@ class LoggedException extends \Exception { return 'An error occured. Sorry.'; } - return $this->getMessage(); + $e = ($this->getPrevious() ?: $this); + return $e->getMessage(); } /** @@ -47,8 +49,9 @@ class LoggedException extends \Exception { return; } + $e = ($this->getPrevious() ?: $this); // build message - $message = date('r', TIME_NOW) . "\n" . $this->getMessage() . "\n\n" . $this->getTraceAsString() . "\n\n\n"; + $message = date('r', TIME_NOW) . "\n" . $e->getMessage() . "\n\n" . $e->getTraceAsString() . "\n\n\n"; // append @file_put_contents($logFile, $message, FILE_APPEND); diff --git a/wcfsetup/install/files/lib/system/exception/SystemException.class.php b/wcfsetup/install/files/lib/system/exception/SystemException.class.php index cd2d68f9fe..227f42014e 100644 --- a/wcfsetup/install/files/lib/system/exception/SystemException.class.php +++ b/wcfsetup/install/files/lib/system/exception/SystemException.class.php @@ -38,9 +38,10 @@ class SystemException extends LoggedException implements IPrintableException { * @param string $message error message * @param integer $code error code * @param string $description description of the error + * @param \Exception $previous repacked Exception */ - public function __construct($message = '', $code = 0, $description = '') { - parent::__construct($message, $code); + public function __construct($message = '', $code = 0, $description = '', \Exception $previous = null) { + parent::__construct($message, $code, $previous); $this->description = $description; } @@ -58,7 +59,8 @@ class SystemException extends LoggedException implements IPrintableException { * @see \Exception::getTraceAsString() */ public function __getTraceAsString() { - $string = preg_replace('/Database->__construct\(.*\)/', 'Database->__construct(...)', $this->getTraceAsString()); + $e = ($this->getPrevious() ?: $this); + $string = preg_replace('/Database->__construct\(.*\)/', 'Database->__construct(...)', $e->getTraceAsString()); $string = preg_replace('/mysqli->mysqli\(.*\)/', 'mysqli->mysqli(...)', $string); return $string; } @@ -81,7 +83,7 @@ class SystemException extends LoggedException implements IPrintableException { // print report echo ''; - + $e = ($this->getPrevious() ?: $this); ?> @@ -155,9 +157,9 @@ class SystemException extends LoggedException implements IPrintableException {

Information:

error message: _getMessage()); ?>
- error code: getCode()); ?>
+ error code: getCode()); ?>
information; ?> - file: getFile()); ?> (getLine(); ?>)
+ file: getFile()); ?> (getLine(); ?>)
php version:
wcf version:
date:
-- 2.20.1