From 6ce3f4bef339a7b2d11489775dcb04e1d3742d6d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 29 Sep 2015 22:55:16 +0200 Subject: [PATCH] Clean up \wcf\system\exception\* --- .../lib/action/AJAXInvokeAction.class.php | 3 +- .../exception/IPrintableException.class.php | 1 + .../exception/LoggedException.class.php | 93 +++---------------- .../exception/NamedUserException.class.php | 5 - .../exception/SystemException.class.php | 4 +- 5 files changed, 15 insertions(+), 91 deletions(-) diff --git a/wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php b/wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php index c1a1f848e7..a0041c72c9 100644 --- a/wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php +++ b/wcfsetup/install/files/lib/action/AJAXInvokeAction.class.php @@ -157,7 +157,8 @@ class AJAXInvokeAction extends AbstractSecureAction { if ($this->inDebugMode) { throw $e; } - + // TODO: This needs to be updated to the new exception handling code. + throw new \Exception('TODO: AJAXInvokeAction::throwException()'); if ($e instanceof InvalidSecurityTokenException) { throw new AJAXException(WCF::getLanguage()->get('wcf.ajax.error.sessionExpired'), AJAXException::SESSION_EXPIRED, $e->getTraceAsString()); } diff --git a/wcfsetup/install/files/lib/system/exception/IPrintableException.class.php b/wcfsetup/install/files/lib/system/exception/IPrintableException.class.php index bc0e745c88..11a20b4099 100644 --- a/wcfsetup/install/files/lib/system/exception/IPrintableException.class.php +++ b/wcfsetup/install/files/lib/system/exception/IPrintableException.class.php @@ -10,6 +10,7 @@ namespace wcf\system\exception; * @package com.woltlab.wcf * @subpackage system.exception * @category Community Framework + * @deprecated 2.2 - Fatal Exceptions are printed automatically, if you need a well styled page use: NamedUserException */ interface IPrintableException { /** diff --git a/wcfsetup/install/files/lib/system/exception/LoggedException.class.php b/wcfsetup/install/files/lib/system/exception/LoggedException.class.php index 022fb2d1b3..0fcf163973 100644 --- a/wcfsetup/install/files/lib/system/exception/LoggedException.class.php +++ b/wcfsetup/install/files/lib/system/exception/LoggedException.class.php @@ -14,33 +14,9 @@ use wcf\util\StringUtil; * @package com.woltlab.wcf * @subpackage system.exception * @category Community Framework + * @deprecated 2.2 - Fatal Exceptions are logged automatically. */ class LoggedException extends \Exception { - /** - * exception id - * @var string - */ - protected $exceptionID = ''; - - /** - * ignore disabled debug mode - * @var boolean - */ - protected $ignoreDebugMode = false; - - /** - * @see \Exception::getMessage() - */ - public function _getMessage() { - // suppresses the original error message - if (!WCF::debugModeIsEnabled() && !$this->ignoreDebugMode) { - return 'An error occured. Sorry.'; - } - - $e = ($this->getPrevious() ?: $this); - return $e->getMessage(); - } - /** * Returns exception id * @@ -48,65 +24,18 @@ class LoggedException extends \Exception { */ public function getExceptionID() { if (empty($this->exceptionID)) { - $this->logError(); - } - - return $this->exceptionID; - } - - /** - * Removes database password from stack trace. - * @see \Exception::getTraceAsString() - */ - public function __getTraceAsString() { - $e = ($this->getPrevious() ?: $this); - $string = preg_replace('/Database->__construct\(.*\)/', 'Database->__construct(...)', $e->getTraceAsString()); - return $string; - } - - /** - * Writes an error to log file. - */ - protected function logError() { - if (!empty($this->exceptionID)) { - return; - } - - $logFile = WCF_DIR . 'log/' . gmdate('Y-m-d', TIME_NOW) . '.txt'; - - // try to create file - @touch($logFile); - - // validate if file exists and is accessible for us - if (!file_exists($logFile) || !is_writable($logFile)) { - /* - We cannot recover if we reached this point, the server admin - is urged to fix his pretty much broken configuration. + try { + \wcf\functions\exception\logThrowable($this); + } + catch (\Exception $e) { + + } + catch (\Throwable $e) { - GLaDOS: Look at you, sailing through the air majestically, like an eagle... piloting a blimp. - */ - return; + } + $this->exceptionID = '*MAYDAY*'; } - $e = ($this->getPrevious() ?: $this); - - // don't forget to update ExceptionLogViewPage, when changing the log file format - $message = gmdate('r', TIME_NOW)."\n". - 'Message: '.$e->getMessage()."\n". - 'File: '.$e->getFile().' ('.$e->getLine().")\n". - 'PHP version: '.phpversion()."\n". - 'WCF version: '.WCF_VERSION."\n". - 'Request URI: '.(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '')."\n". - 'Referrer: '.(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '')."\n". - 'User-Agent: '.(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '')."\n". - 'Information: '.JSON::encode($this->information)."\n". - "Stacktrace: \n ".implode("\n ", explode("\n", $this->__getTraceAsString()))."\n"; - - // calculate Exception-ID - $this->exceptionID = StringUtil::getHash($message); - $message = "<<<<<<<<".$this->exceptionID."<<<<\n".$message."<<<<\n\n"; - - // append - @file_put_contents($logFile, $message, FILE_APPEND); + return $this->exceptionID; } } diff --git a/wcfsetup/install/files/lib/system/exception/NamedUserException.class.php b/wcfsetup/install/files/lib/system/exception/NamedUserException.class.php index a2676fade3..0ae316833e 100644 --- a/wcfsetup/install/files/lib/system/exception/NamedUserException.class.php +++ b/wcfsetup/install/files/lib/system/exception/NamedUserException.class.php @@ -13,11 +13,6 @@ use wcf\system\WCF; * @category Community Framework */ class NamedUserException extends UserException { - /** - * @see \wcf\system\exception\LoggedException::$ignoreDebugMode - */ - protected $ignoreDebugMode = true; - /** * Shows a styled page with the given error message. */ diff --git a/wcfsetup/install/files/lib/system/exception/SystemException.class.php b/wcfsetup/install/files/lib/system/exception/SystemException.class.php index ef1e4458b9..4c19625f2e 100644 --- a/wcfsetup/install/files/lib/system/exception/SystemException.class.php +++ b/wcfsetup/install/files/lib/system/exception/SystemException.class.php @@ -58,7 +58,5 @@ class SystemException extends LoggedException { /** * @see \wcf\system\exception\IPrintableException::show() */ - public function show() { - - } + public function show() { } } -- 2.20.1