From 339fd234a51b35f2ed1e8519bd0a396ebd196163 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 19 Mar 2020 00:58:30 +0900 Subject: [PATCH] Show where an Exception was thrown or error object was returned MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 관리자에게만 표시함 - 오류 화면을 표시하는 방식에 따라서는 표시되지 않을 수 있음 - 코어 내부에서 발생하는 오류는 표시되지 않을 수 있음 - message 모듈 스킨에 의존함 --- classes/context/Context.class.php | 16 ++++++++++++-- classes/module/ModuleHandler.class.php | 2 +- classes/module/ModuleObject.class.php | 21 ++++++++++++++++++- classes/object/Object.class.php | 15 ++++++++++++- .../m.skins/default/system_message.html | 3 +++ modules/message/message.view.php | 9 +++++++- modules/message/skins/default/message.css | 2 ++ .../message/skins/default/system_message.html | 7 ++++++- .../skins/simple_world/system_message.html | 9 ++++++-- .../skins/xedition/system_message.html | 7 ++++++- 10 files changed, 81 insertions(+), 10 deletions(-) diff --git a/classes/context/Context.class.php b/classes/context/Context.class.php index bf4142daa..fed960b3c 100644 --- a/classes/context/Context.class.php +++ b/classes/context/Context.class.php @@ -1524,7 +1524,7 @@ class Context * @param string $message * @return void */ - public static function displayErrorPage($title = 'Error', $message = '', $status = 500) + public static function displayErrorPage($title = 'Error', $message = '', $status = 500, $location = '') { // Change current directory to the Rhymix installation path. chdir(\RX_BASEDIR); @@ -1541,6 +1541,18 @@ class Context $oMessageObject->setHttpStatusCode($status); } + // Find out the caller's location. + if (!$location) + { + $backtrace = debug_backtrace(false); + $caller = array_shift($backtrace); + $location = $caller['file'] . ':' . $caller['line']; + if (starts_with(\RX_BASEDIR, $location)) + { + $location = substr($location, strlen(\RX_BASEDIR)); + } + } + if (in_array(Context::getRequestMethod(), array('XMLRPC', 'JSON', 'JS_CALLBACK'))) { $oMessageObject->setMessage(trim($title . "\n\n" . $message)); @@ -1548,7 +1560,7 @@ class Context else { $oMessageObject->setMessage($title); - $oMessageObject->dispMessage($message); + $oMessageObject->dispMessage($message, $location); } // Display the message. diff --git a/classes/module/ModuleHandler.class.php b/classes/module/ModuleHandler.class.php index 45a8035fb..de36828c0 100644 --- a/classes/module/ModuleHandler.class.php +++ b/classes/module/ModuleHandler.class.php @@ -993,7 +993,7 @@ class ModuleHandler extends Handler $oMessageObject = self::getModuleInstance('message', $type); $oMessageObject->setError(-1); $oMessageObject->setMessage($this->error); - $oMessageObject->dispMessage(); + $oMessageObject->dispMessage(null, $oModule->get('rx_error_location')); // display Error Page if(!in_array($oMessageObject->getHttpStatusCode(), array(200, 403))) diff --git a/classes/module/ModuleObject.class.php b/classes/module/ModuleObject.class.php index 4cddf51af..ba3572eee 100644 --- a/classes/module/ModuleObject.class.php +++ b/classes/module/ModuleObject.class.php @@ -363,12 +363,17 @@ class ModuleObject extends BaseObject $this->setError(-1); $this->setMessage($msg_code); + // Get backtrace + $backtrace = debug_backtrace(false); + $caller = array_shift($backtrace); + $location = $caller['file'] . ':' . $caller['line']; + // Error message display by message module $type = Mobile::isFromMobilePhone() ? 'mobile' : 'view'; $oMessageObject = ModuleHandler::getModuleInstance('message', $type); $oMessageObject->setError(-1); $oMessageObject->setMessage($msg_code); - $oMessageObject->dispMessage(); + $oMessageObject->dispMessage(null, $location); $this->setTemplatePath($oMessageObject->getTemplatePath()); $this->setTemplateFile($oMessageObject->getTemplateFile()); @@ -597,6 +602,8 @@ class ModuleObject extends BaseObject catch (Rhymix\Framework\Exception $e) { $output = new BaseObject(-2, $e->getMessage()); + $location = $e->getFile() . ':' . $e->getLine(); + $output->add('rx_error_location', $location); } } else @@ -609,6 +616,10 @@ class ModuleObject extends BaseObject { $this->setError($output->getError()); $this->setMessage($output->getMessage()); + if($output->getError() && $output->get('rx_error_location')) + { + $this->add('rx_error_location', $output->get('rx_error_location')); + } $original_output = clone $output; } else @@ -622,6 +633,10 @@ class ModuleObject extends BaseObject { $this->setError($triggerOutput->getError()); $this->setMessage($triggerOutput->getMessage()); + if($output->get('rx_error_location')) + { + $this->add('rx_error_location', $output->get('rx_error_location')); + } return FALSE; } @@ -639,6 +654,10 @@ class ModuleObject extends BaseObject { $this->setError($output->getError()); $this->setMessage($output->getMessage()); + if($output->get('rx_error_location')) + { + $this->add('rx_error_location', $output->get('rx_error_location')); + } return FALSE; } diff --git a/classes/object/Object.class.php b/classes/object/Object.class.php index f56bc3306..036c1ab5c 100644 --- a/classes/object/Object.class.php +++ b/classes/object/Object.class.php @@ -44,6 +44,19 @@ class BaseObject { $this->setError($error); $this->setMessage($message); + + if ($error) + { + $backtrace = debug_backtrace(false); + $caller = array_shift($backtrace); + $nextcaller = array_shift($backtrace); + if ($nextcaller && $nextcaller['function'] === 'createObject') + { + $caller = $nextcaller; + } + $location = $caller['file'] . ':' . $caller['line']; + $this->add('rx_error_location', $location); + } } /** @@ -298,4 +311,4 @@ if (version_compare(PHP_VERSION, '7.2', '<')) } /* End of file Object.class.php */ -/* Location: ./classes/object/Object.class.php */ \ No newline at end of file +/* Location: ./classes/object/Object.class.php */ diff --git a/modules/message/m.skins/default/system_message.html b/modules/message/m.skins/default/system_message.html index 5ac43b9b6..1369918af 100644 --- a/modules/message/m.skins/default/system_message.html +++ b/modules/message/m.skins/default/system_message.html @@ -6,6 +6,9 @@
{$system_message_detail}
+
+ {$system_message_location} +

{$XE_VALIDATOR_MESSAGE}

diff --git a/modules/message/message.view.php b/modules/message/message.view.php index fd3169eec..d76c2a1b3 100644 --- a/modules/message/message.view.php +++ b/modules/message/message.view.php @@ -17,7 +17,7 @@ class messageView extends message /** * @brief Display messages */ - function dispMessage($detail = null) + function dispMessage($detail = null, $location = null) { // Get configurations (using module model object) $oModuleModel = getModel('module'); @@ -47,10 +47,17 @@ class messageView extends message { if(strncasecmp('https://', Context::getRequestUri(), 8) === 0) $ssl_mode = true; } + + // Remove basedir from location (if any) + if ($location && starts_with(\RX_BASEDIR, $location)) + { + $location = substr($location, strlen(\RX_BASEDIR)); + } Context::set('ssl_mode', $ssl_mode); Context::set('system_message', nl2br($this->getMessage())); Context::set('system_message_detail', nl2br($detail)); + Context::set('system_message_location', escape($location)); $this->setTemplateFile('system_message'); diff --git a/modules/message/skins/default/message.css b/modules/message/skins/default/message.css index 1e30d1154..ccde3f349 100644 --- a/modules/message/skins/default/message.css +++ b/modules/message/skins/default/message.css @@ -16,6 +16,8 @@ body, #access table, #access input, #access textarea, #access select, #access bu #access>.login-footer:after{display:table;line-height:0;content:"";clear:both} #access .control-group{position:relative;padding:0 14px 0 0;margin:0;clear:both} #access .control-group:before{content:"";display:block;clear:both} +#access .message{padding:0.8em 1em} +#access .message.location{word-break:break-all} #access form{margin:0} #access fieldset{margin:0} #access label{cursor:pointer;display:inline-block} diff --git a/modules/message/skins/default/system_message.html b/modules/message/skins/default/system_message.html index bd63106d3..e1744d30a 100644 --- a/modules/message/skins/default/system_message.html +++ b/modules/message/skins/default/system_message.html @@ -8,7 +8,12 @@