From 40f9fe18a2fa6c3f18adbdfa9e5800e3f67d268a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 15 Apr 2013 15:25:26 +0200 Subject: [PATCH] Exception ID is now properly disabled --- wcfsetup/install/files/js/WCF.js | 6 +++- .../lib/action/AJAXInvokeAction.class.php | 6 ++-- .../system/exception/AJAXException.class.php | 7 +++-- .../exception/LoggedException.class.php | 29 ++++++++++++++++--- .../exception/SystemException.class.php | 7 ++--- 5 files changed, 40 insertions(+), 15 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index fc7eacc28f..ec467da97b 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -1570,7 +1570,11 @@ WCF.Action.Proxy = Class.extend({ } if (!this._suppressErrors && $showError !== false) { - $('

' + $data.message + '

Stacktrace:

' + $data.stacktrace + '

').wcfDialog({ title: WCF.Language.get('wcf.global.error.title') }); + var $details = ''; + if ($data.stacktrace) $details = '

Stacktrace:

' + $data.stacktrace + '

'; + else if ($data.exceptionID) $details = '

Exception ID: ' + $data.exceptionID + '

'; + + $('

' + $data.message + '

' + $details + '
').wcfDialog({ title: WCF.Language.get('wcf.global.error.title') }); } } // failed to parse JSON diff --git a/wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php b/wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php index 02e1308d42..410fa64484 100644 --- a/wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php +++ b/wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php @@ -1,5 +1,7 @@ get('wcf.ajax.error.permissionDenied'), AJAXException::INSUFFICIENT_PERMISSIONS, $e->getTraceAsString()); } else if ($e instanceof SystemException) { - throw new AJAXException($e->getMessage(), AJAXException::INTERNAL_ERROR, $e->__getTraceAsString()); + throw new AJAXException($e->getMessage(), AJAXException::INTERNAL_ERROR, $e->__getTraceAsString(), array(), $e->getExceptionID()); } else if ($e instanceof UserInputException) { // repackage as ValidationActionException @@ -170,7 +172,7 @@ class AJAXInvokeAction extends AbstractSecureAction { )); } else { - throw new AJAXException($e->getMessage(), AJAXException::INTERNAL_ERROR, $e->getTraceAsString()); + throw new AJAXException($e->getMessage(), AJAXException::INTERNAL_ERROR, $e->getTraceAsString(), array(), ($e instanceof LoggedException ? $e->getExceptionID() : '')); } } diff --git a/wcfsetup/install/files/lib/system/exception/AJAXException.class.php b/wcfsetup/install/files/lib/system/exception/AJAXException.class.php index 6a11328553..649a3ca782 100644 --- a/wcfsetup/install/files/lib/system/exception/AJAXException.class.php +++ b/wcfsetup/install/files/lib/system/exception/AJAXException.class.php @@ -50,9 +50,11 @@ class AJAXException extends LoggedException { * @param string $message * @param boolean $isDoomsday * @param string $stacktrace + * @param array $returnValues + * @param string $exceptionID * @param array $returnValues */ - public function __construct($message, $errorType = self::INTERNAL_ERROR, $stacktrace = null, $returnValues = array()) { + public function __construct($message, $errorType = self::INTERNAL_ERROR, $stacktrace = null, $returnValues = array(), $exceptionID = '') { if ($stacktrace === null) $stacktrace = $this->getTraceAsString(); if (WCF::debugModeIsEnabled()) { @@ -97,11 +99,10 @@ class AJAXException extends LoggedException { header('HTTP/1.0 503 Service Unavailable'); $responseData['code'] = self::INTERNAL_ERROR; + $responseData['exceptionID'] = $exceptionID; if (!WCF::debugModeIsEnabled()) { $responseData['message'] = WCF::getLanguage()->get('wcf.ajax.error.internalError'); } - - $this->logError(); break; } diff --git a/wcfsetup/install/files/lib/system/exception/LoggedException.class.php b/wcfsetup/install/files/lib/system/exception/LoggedException.class.php index 832b0fd971..732f65f271 100644 --- a/wcfsetup/install/files/lib/system/exception/LoggedException.class.php +++ b/wcfsetup/install/files/lib/system/exception/LoggedException.class.php @@ -15,6 +15,12 @@ use wcf\util\StringUtil; * @category Community Framework */ class LoggedException extends \Exception { + /** + * exception id + * @var string + */ + protected $exceptionID = ''; + /** * ignore disabled debug mode * @var boolean @@ -34,10 +40,27 @@ class LoggedException extends \Exception { return $e->getMessage(); } + /** + * Returns exception id + * + * @return string + */ + public function getExceptionID() { + if (empty($this->exceptionID)) { + $this->logError(); + } + + return $this->exceptionID; + } + /** * Writes an error to log file. */ protected function logError() { + if (!empty($this->exceptionID)) { + return; + } + $logFile = WCF_DIR . 'log/' . date('Y-m-d', TIME_NOW) . '.txt'; // try to create file @@ -66,12 +89,10 @@ class LoggedException extends \Exception { "Stacktrace: \n ".implode("\n ", explode("\n", $e->getTraceAsString()))."\n"; // calculate Exception-ID - $id = StringUtil::getHash($message); - $message = "<<<<<<<<".$id."<<<<\n".$message."<<<<\n\n"; + $this->exceptionID = StringUtil::getHash($message); + $message = "<<<<<<<<".$this->exceptionID."<<<<\n".$message."<<<<\n\n"; // append @file_put_contents($logFile, $message, FILE_APPEND); - - return $id; } } diff --git a/wcfsetup/install/files/lib/system/exception/SystemException.class.php b/wcfsetup/install/files/lib/system/exception/SystemException.class.php index 12081c862e..88679b8d7c 100644 --- a/wcfsetup/install/files/lib/system/exception/SystemException.class.php +++ b/wcfsetup/install/files/lib/system/exception/SystemException.class.php @@ -70,9 +70,6 @@ class SystemException extends LoggedException implements IPrintableException { * @see wcf\system\exception\IPrintableException::show() */ public function show() { - // log error - $exceptionID = $this->logError(); - // send status code @header('HTTP/1.1 503 Service Unavailable'); @@ -157,7 +154,7 @@ class SystemException extends LoggedException implements IPrintableException {

Information:

- id:
+ id: getExceptionID(); ?>
error message: _getMessage()); ?>
error code: getCode()); ?>
information; ?> @@ -176,7 +173,7 @@ class SystemException extends LoggedException implements IPrintableException {

Information:

- id:
+ id: getExceptionID(); ?>
Send this ID to the administrator of this website to report this issue.

-- 2.20.1