From: Alexander Ebert Date: Mon, 15 Apr 2013 13:25:26 +0000 (+0200) Subject: Exception ID is now properly disabled X-Git-Tag: 2.0.0_Beta_1~354 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=40f9fe18a2fa6c3f18adbdfa9e5800e3f67d268a;p=GitHub%2FWoltLab%2FWCF.git Exception ID is now properly disabled --- 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.