Move friendly error message feature to Message module

This commit is contained in:
Kijin Sung 2023-08-08 00:49:14 +09:00
parent 26710e2675
commit e31704ffc2
9 changed files with 41 additions and 20 deletions

View file

@ -632,17 +632,11 @@ class Debug
{ {
$log_entry = str_replace("\0", '', sprintf('%s #%d "%s" in %s on line %d (via %s on line %d)', $log_entry = str_replace("\0", '', sprintf('%s #%d "%s" in %s on line %d (via %s on line %d)',
get_class($e), $e->getCode(), $e->getMessage(), $caller_errfile, $caller_errline, $errfile, $e->getLine())); get_class($e), $e->getCode(), $e->getMessage(), $caller_errfile, $caller_errline, $errfile, $e->getLine()));
$friendly_entry = $log_entry;
} }
else else
{ {
$log_entry = str_replace("\0", '', sprintf('%s #%d "%s" in %s on line %d', $log_entry = str_replace("\0", '', sprintf('%s #%d "%s" in %s on line %d',
get_class($e), $e->getCode(), $e->getMessage(), $errfile, $e->getLine())); get_class($e), $e->getCode(), $e->getMessage(), $errfile, $e->getLine()));
$friendly_entry = $log_entry;
if ($e->getMessage() === 'Class "Object" not found')
{
$friendly_entry .= "\n\n" . lang('msg_baseobject_fix');
}
} }
if (!isset(self::$_config['write_error_log']) || self::$_config['write_error_log'] !== 'none') if (!isset(self::$_config['write_error_log']) || self::$_config['write_error_log'] !== 'none')
@ -651,7 +645,7 @@ class Debug
} }
// Display the error screen. // Display the error screen.
self::displayErrorScreen($friendly_entry); self::displayErrorScreen($log_entry);
exit; exit;
} }
@ -741,7 +735,7 @@ class Debug
* @param string $message * @param string $message
* @return void * @return void
*/ */
public static function displayErrorScreen($message) public static function displayErrorScreen($message, $location = '')
{ {
// Do not display error screen in CLI. // Do not display error screen in CLI.
if (php_sapi_name() === 'cli') if (php_sapi_name() === 'cli')
@ -773,7 +767,7 @@ class Debug
// Display a generic error page. // Display a generic error page.
try try
{ {
\Context::displayErrorPage($title, $message, 500); \Context::displayErrorPage($title, $message, 500, $location);
} }
catch (\Error $e) catch (\Error $e)
{ {

View file

@ -342,7 +342,6 @@ $lang->filter['invalid_number'] = 'The format of %s is invalid. Please enter num
$lang->filter['invalid_float'] = 'The format of %s is invalid. Please enter numbers only.'; $lang->filter['invalid_float'] = 'The format of %s is invalid. Please enter numbers only.';
$lang->filter['invalid_extension'] = 'The format of %s is invalid. e.g. gif, jpg, png'; $lang->filter['invalid_extension'] = 'The format of %s is invalid. e.g. gif, jpg, png';
$lang->security_warning_embed = 'Due to security concern, administrators are not allowed to view embedded items.<BR /> To view them, please use another non-administrator ID.'; $lang->security_warning_embed = 'Due to security concern, administrators are not allowed to view embedded items.<BR /> To view them, please use another non-administrator ID.';
$lang->msg_baseobject_fix = 'Object → BaseObject conversion is required in a third-party program. Please fix it by consulting the file name and line number shown above.';
$lang->msg_pc_to_mobile = 'View mobile optimized version of this page'; $lang->msg_pc_to_mobile = 'View mobile optimized version of this page';
$lang->cmd_yes = 'Yes'; $lang->cmd_yes = 'Yes';
$lang->cmd_no = 'No'; $lang->cmd_no = 'No';

View file

@ -346,7 +346,6 @@ $lang->filter['invalid_float'] = '%s의 형식이 잘못되었습니다. 숫자
$lang->filter['invalid_extension'] = '%s의 형식이 잘못되었습니다. gif, jpg, png 등 쉼표로 구분하여 입력해야 합니다.'; $lang->filter['invalid_extension'] = '%s의 형식이 잘못되었습니다. gif, jpg, png 등 쉼표로 구분하여 입력해야 합니다.';
$lang->security_invalid_session = '바르지 않은 접근입니다. 인증을 위해 다시 로그인해야 합니다.'; $lang->security_invalid_session = '바르지 않은 접근입니다. 인증을 위해 다시 로그인해야 합니다.';
$lang->security_warning_embed = '보안 문제로 관리자 아이디로는 embed를 볼 수 없습니다. 확인하려면 다른 아이디로 접속하세요'; $lang->security_warning_embed = '보안 문제로 관리자 아이디로는 embed를 볼 수 없습니다. 확인하려면 다른 아이디로 접속하세요';
$lang->msg_baseobject_fix = 'Object → BaseObject 변환이 필요한 서드파티 자료가 있습니다. 위의 에러 메시지에 포함된 파일명과 줄 번호를 참고하여 수정하세요.';
$lang->msg_pc_to_mobile = '모바일에 최적화된 화면으로 보기'; $lang->msg_pc_to_mobile = '모바일에 최적화된 화면으로 보기';
$lang->cmd_yes = '예'; $lang->cmd_yes = '예';
$lang->cmd_no = '아니오'; $lang->cmd_no = '아니오';
@ -381,4 +380,4 @@ $lang->image_quality = '화질';
$lang->standard = '표준'; $lang->standard = '표준';
$lang->unlimited = '제한 없음'; $lang->unlimited = '제한 없음';
$lang->admin = '관리자'; $lang->admin = '관리자';
$lang->stop = '중지'; $lang->stop = '중지';

View file

@ -1,3 +1,5 @@
<?php <?php
$lang->message = 'Display Errors'; $lang->message = 'Display Errors';
$lang->about_skin = 'You may select skins for error messages.'; $lang->about_skin = 'You may select skins for error messages.';
$lang->msg_administrator_login = 'Administrator Login';
$lang->error_help['baseobject'] = 'Object → BaseObject conversion is required in a third-party program. Please fix it by consulting the file name and line number shown above.';

View file

@ -2,3 +2,4 @@
$lang->message = '오류 표시'; $lang->message = '오류 표시';
$lang->about_skin = '오류 메시지용 스킨을 지정할 수 있습니다.'; $lang->about_skin = '오류 메시지용 스킨을 지정할 수 있습니다.';
$lang->msg_administrator_login = '관리자 로그인'; $lang->msg_administrator_login = '관리자 로그인';
$lang->error_help['baseobject'] = 'Object → BaseObject 변환이 필요한 서드파티 자료가 있습니다. 위의 에러 메시지에 포함된 파일명과 줄 번호를 참고하여 수정하세요.';

View file

@ -6,6 +6,9 @@
<div class="message" cond="$system_message_detail"> <div class="message" cond="$system_message_detail">
{$system_message_detail} {$system_message_detail}
</div> </div>
<div class="message help" cond="$system_message_help">
{$system_message_help}
</div>
<div class="message location" cond="$system_message_location"> <div class="message location" cond="$system_message_location">
{$system_message_location} {$system_message_location}
</div> </div>

View file

@ -7,17 +7,10 @@
*/ */
class MessageView extends Message class MessageView extends Message
{ {
/**
* @brief Initialization
*/
function init()
{
}
/** /**
* @brief Display messages * @brief Display messages
*/ */
function dispMessage($detail = null, $location = null) public function dispMessage($detail = null, $location = null)
{ {
// Get skin configuration // Get skin configuration
$config = ModuleModel::getModuleConfig('message') ?: new stdClass; $config = ModuleModel::getModuleConfig('message') ?: new stdClass;
@ -79,6 +72,7 @@ class MessageView extends Message
Context::set('ssl_mode', \RX_SSL); Context::set('ssl_mode', \RX_SSL);
Context::set('system_message', nl2br($this->getMessage())); Context::set('system_message', nl2br($this->getMessage()));
Context::set('system_message_detail', nl2br($detail)); Context::set('system_message_detail', nl2br($detail));
Context::set('system_message_help', self::getErrorHelp($detail));
Context::set('system_message_location', escape($location)); Context::set('system_message_location', escape($location));
if ($this->getError()) if ($this->getError())
@ -101,6 +95,29 @@ class MessageView extends Message
$this->setHttpStatusCode(403); $this->setHttpStatusCode(403);
} }
} }
/**
* Get friendly help message for common types of errors.
*
* @param string $error_message
* @return string
*/
public static function getErrorHelp(string $error_message): string
{
$regexp_list = [
'/Class [\'"]Object[\'"] not found/' => 'baseobject',
];
foreach ($regexp_list as $regexp => $key)
{
if (preg_match($regexp, $error_message))
{
return lang('message.error_help.' . $key);
}
}
return '';
}
} }
/* End of file message.view.php */ /* End of file message.view.php */
/* Location: ./modules/message/message.view.php */ /* Location: ./modules/message/message.view.php */

View file

@ -11,6 +11,9 @@
<div class="message" cond="$system_message_detail"> <div class="message" cond="$system_message_detail">
{$system_message_detail} {$system_message_detail}
</div> </div>
<div class="message help" cond="$system_message_help">
{$system_message_help}
</div>
<div class="message location" cond="$system_message_location"> <div class="message location" cond="$system_message_location">
{$system_message_location} {$system_message_location}
</div> </div>

View file

@ -8,6 +8,9 @@
<div class="message" cond="$system_message_detail"> <div class="message" cond="$system_message_detail">
{$system_message_detail} {$system_message_detail}
</div> </div>
<div class="message help" cond="$system_message_help">
{$system_message_help}
</div>
<div class="message location" cond="$system_message_location"> <div class="message location" cond="$system_message_location">
{$system_message_location} {$system_message_location}
</div> </div>