Exception ID is now properly disabled
authorAlexander Ebert <ebert@woltlab.com>
Mon, 15 Apr 2013 13:25:26 +0000 (15:25 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 15 Apr 2013 13:25:26 +0000 (15:25 +0200)
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php
wcfsetup/install/files/lib/system/exception/AJAXException.class.php
wcfsetup/install/files/lib/system/exception/LoggedException.class.php
wcfsetup/install/files/lib/system/exception/SystemException.class.php

index fc7eacc28ff380d5dbe92204c95e788c96f489ec..ec467da97b0248df508cbfb29855e8d51f7bba31 100755 (executable)
@@ -1570,7 +1570,11 @@ WCF.Action.Proxy = Class.extend({
                        }
                        
                        if (!this._suppressErrors && $showError !== false) {
-                               $('<div class="ajaxDebugMessage"><p>' + $data.message + '</p><p>Stacktrace:</p><p>' + $data.stacktrace + '</p></div>').wcfDialog({ title: WCF.Language.get('wcf.global.error.title') });
+                               var $details = '';
+                               if ($data.stacktrace) $details = '<br /><p>Stacktrace:</p><p>' + $data.stacktrace + '</p>';
+                               else if ($data.exceptionID) $details = '<br /><p>Exception ID: <code>' + $data.exceptionID + '</code></p>';
+                               
+                               $('<div class="ajaxDebugMessage"><p>' + $data.message + '</p>' + $details + '</div>').wcfDialog({ title: WCF.Language.get('wcf.global.error.title') });
                        }
                }
                // failed to parse JSON
index 02e1308d42cfca139282665cbb6541822e074f2f..410fa644842bfbcd2c1956daf896f425896bcb52 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 namespace wcf\action;
+use wcf\system\exception\LoggedException;
+
 use wcf\system\exception\AJAXException;
 use wcf\system\exception\IllegalLinkException;
 use wcf\system\exception\PermissionDeniedException;
@@ -152,7 +154,7 @@ class AJAXInvokeAction extends AbstractSecureAction {
                        throw new AJAXException(WCF::getLanguage()->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() : ''));
                }
        }
        
index 6a1132855318469e400b131b7c109991e30093c2..649a3ca78261205640802a55e01e9b70f57d9280 100644 (file)
@@ -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<mixed>    $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;
                }
                
index 832b0fd9712f54221a0c6469e87412d94f89ff4e..732f65f2715314298cf1a80e72b944b76e7658b7 100644 (file)
@@ -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;
        }
 }
index 12081c862e174d40d5596e4e24c43b15951f5b3d..88679b8d7c9235c0e8e9f6010575e8c30d60e780 100644 (file)
@@ -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 {
                                                        
                                                        <h2>Information:</h2>
                                                        <p>
-                                                               <b>id:</b> <code><?php echo $exceptionID; ?></code><br>
+                                                               <b>id:</b> <code><?php echo $this->getExceptionID(); ?></code><br>
                                                                <b>error message:</b> <?php echo StringUtil::encodeHTML($this->_getMessage()); ?><br>
                                                                <b>error code:</b> <?php echo intval($e->getCode()); ?><br>
                                                                <?php echo $this->information; ?>
@@ -176,7 +173,7 @@ class SystemException extends LoggedException implements IPrintableException {
                                                <div>
                                                        <h2>Information:</h2>
                                                        <p>
-                                                               <b>id:</b> <code><?php echo $exceptionID; ?></code><br>
+                                                               <b>id:</b> <code><?php echo $this->getExceptionID(); ?></code><br>
                                                                Send this ID to the administrator of this website to report this issue.
                                                        </p>
                                                </div>