From 614e246665775cdde5d85a623f450988e21d6382 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 25 Feb 2016 21:55:09 +0100 Subject: [PATCH] Overhauled exception view --- wcfsetup/install/files/lib/core.functions.php | 467 ++++++++++++------ wcfsetup/install/lang/de.xml | 15 +- wcfsetup/install/lang/en.xml | 16 +- 3 files changed, 346 insertions(+), 152 deletions(-) diff --git a/wcfsetup/install/files/lib/core.functions.php b/wcfsetup/install/files/lib/core.functions.php index e00eef70e7..275316d324 100644 --- a/wcfsetup/install/files/lib/core.functions.php +++ b/wcfsetup/install/files/lib/core.functions.php @@ -49,8 +49,7 @@ namespace wcf\functions\exception { use wcf\util\FileUtil; use wcf\util\StringUtil; - function logThrowable($e) { - $logFile = WCF_DIR . 'log/' . gmdate('Y-m-d', TIME_NOW) . '.txt'; + function logThrowable($logFile, $e) { touch($logFile); // don't forget to update ExceptionLogViewPage, when changing the log file format @@ -97,7 +96,53 @@ namespace wcf\functions\exception { } function printThrowable($e) { - $exceptionID = logThrowable($e); // TODO + $logFile = WCF_DIR . 'log/' . gmdate('Y-m-d', TIME_NOW) . '.txt'; + $exceptionID = logThrowable($logFile, $e); // TODO + + $exceptionTitle = $exceptionSubtitle = $exceptionExplanation = ''; + $logFile = sanitizePath($logFile); + try { + $exceptionTitle = WCF::getLanguage()->get('wcf.global.exception.title', true); + $exceptionSubtitle = str_replace('{$exceptionID}', $exceptionID, WCF::getLanguage()->get('wcf.global.exception.subtitle', true)); + $exceptionExplanation= str_replace('{$logFile}', $logFile, WCF::getLanguage()->get('wcf.global.exception.explanation', true)); + } + catch (\Exception $e) { + // ignore + } + catch (\Throwable $e) { + // ignore + } + + if (!$exceptionTitle || !$exceptionSubtitle || !$exceptionExplanation) { + // one or more failed, fallback to english + $exceptionTitle = 'An error has occured'; + $exceptionSubtitle = 'Internal error code: {$exceptionID}'; + $exceptionExplanation = <<What happened?

+

An error has occured while trying to handle your request and execution has been terminated. Please forward the above error code to the site administrator.

+

 

+

+ The error code can be used by an administrator to lookup the full error message in the Administration Control Panel via “Logs » Errors”. + In addition the error has been writen to the log file located at {$logFile} and can be accessed with a FTP program or similar. +

+

 

+

Notice: The error code was randomly generated and has no use beyond looking up the full message.

+EXPLANATION; + + } + + /* + * A notice on the HTML used below: + * + * It might appear a bit weird to use

all over the place where semantically + * other elements would fit in way better. The reason behind this is that we avoid + * inheriting unwanted styles (e.g. exception displayed in an overlay) and that + * the output needs to be properly readable when copied & pasted somewhere. + * + * Besides the visual appearance, the output was built to provide a maximum of + * compatibility and readability when pasted somewhere else, e.g. a WYSIWYG editor + * without the potential of messing up the formatting and thus harming the readability. + */ ?> @@ -106,137 +151,261 @@ namespace wcf\functions\exception { Fatal Error - + + - - -

- -

Fatal Error: getMessage()); ?>

- -

Fatal Error

- -
- What happened? -

An unrecoverable error occured while trying to handle your request. The internal error code is as follows:

-

Please send this code to the administrator to help him fix the issue.

-

If you are the administrator you can view the complete error message at "ACP > Logs > Errors" einsehen. The error code itself is worthless for the support!

- '; - try { - $message = str_replace('{$exceptionID}', $exceptionID, WCF::getLanguage()->get('wcf.global.error.exception', true)); + + .exceptionFieldValue { + font-size: 18px; + } + + .exceptionSystemInformation, + .exceptionErrorDetails, + .exceptionStacktrace { + list-style-type: none; + } + + .exceptionSystemInformation > li:not(:first-child), + .exceptionErrorDetails > li:not(:first-child) { + margin-top: 10px; + } + + .exceptionStacktrace { + display: block; + margin-top: 5px; + overflow: auto; + padding-bottom: 20px; + } + + .exceptionStacktraceFile, + .exceptionStacktraceFile span, + .exceptionStacktraceCall, + .exceptionStacktraceCall span { + font-family: monospace !important; + white-space: nowrap !important; + } + + .exceptionStacktraceCall + .exceptionStacktraceFile { + margin-top: 5px; + } + + .exceptionStacktraceCall { + padding-left: 40px; + } + + .exceptionStacktraceCall, + .exceptionStacktraceCall span { + color: rgb(102, 102, 102) !important; + font-size: 13px !important; + } + + /* mobile */ + @media (max-width: 767px) { + .exceptionBoundary { + min-width: 320px; + padding: 0 10px; } - catch (\Exception $e) { - + + .exceptionText .exceptionInlineCodeWrapper { + display: inline-block; + overflow: auto; } - catch (\Throwable $e) { - + + .exceptionErrorCode .exceptionInlineCode { + font-size: 13px; + padding: 2px 5px; } - echo $message; - ?> + } + + /* desktop */ + @media (min-width: 768px) { + .exceptionBoundary { + margin: 0 auto; + max-width: 1400px; + min-width: 1200px; + padding: 0 10px; + } + + .exceptionSystemInformation { + display: flex; + flex-wrap: wrap; + } + + .exceptionSystemInformation1, + .exceptionSystemInformation3, + .exceptionSystemInformation5 { + flex: 0 0 200px; + margin: 0 0 10px 0 !important; + } + + .exceptionSystemInformation2, + .exceptionSystemInformation4, + .exceptionSystemInformation6 { + flex: 0 0 calc(100% - 210px); + margin: 0 0 10px 10px !important; + max-width: calc(100% - 210px); + } + + .exceptionSystemInformation1 { order: 1; } + .exceptionSystemInformation2 { order: 2; } + .exceptionSystemInformation3 { order: 3; } + .exceptionSystemInformation4 { order: 4; } + .exceptionSystemInformation5 { order: 5; } + .exceptionSystemInformation6 { order: 6; } + + .exceptionSystemInformation .exceptionFieldValue { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } + } + + + +
+
+
+

+

+
+
+ +
+
-
-

System Information

-
-
PHP Version
-
WCF Version
-
Date
-
Request URI
-
Referrer
-
User Agent
-
Peak Memory Usage
/ Byte (/ MiB)
-
+
+

System Information

+
    +
  • +

    PHP Version:

    +

    +
  • +
  • +

    WCF Version:

    +

    +
  • +
  • +

    Peak Memory Usage:

    +

    / MiB

    +
  • +
  • +

    Request URI:

    +

    +
  • +
  • +

    Referrer:

    +

    +
  • +
  • +

    User Agent:

    +

    +
  • +
+ -
-

getPrevious() && !$first) { echo "Original "; } else if ($e->getPrevious() && $first) { echo "Final "; } ?>Error

+
+

getPrevious() && !$first) { echo "Original "; } else if ($e->getPrevious() && $first) { echo "Final "; } ?>Error

getDescription()) { ?> -

getDescription(); ?>

+

getDescription(); ?>

-
-
Error Class
-
Error Message
getMessage()); ?>
- getCode()) { ?>
Error Code
getCode()); ?>
-
File
getFile())); ?> (getLine(); ?>)
+
    +
  • +

    Error Message:

    +

    getMessage()); ?>

    +
  • + getCode()) { ?> +
  • +

    Error Code:

    +

    getCode()); ?>

    +
  • + +
  • +

    File:

    +

    getFile())); ?> (getLine(); ?>)

    +
  • + getExtraInformation() as list($key, $value)) { - echo "
    ".StringUtil::encodeHTML($key)."
    ".StringUtil::encodeHTML($value)."
    "; + ?> +
  • +

    :

    +

    +
  • + -
    Stack Trace
    -
    "'.StringUtil::encodeHTML(addcslashes(StringUtil::truncate($item, 25, StringUtil::HELLIP, true), "\n")).'"'; - case 'boolean': - return $item ? 'true' : 'false'; - case 'array': - $keys = array_keys($item); - if (count($keys) > 5) return "[ ".count($keys)." items ]"; - return '[ '.implode(', ', array_map(function ($item) { - return $item.' => '; - }, $keys)).']'; - case 'object': - return get_class($item); - } - }, $trace[$i]['args'])); - echo ")\n"; - } - ?>
    -
+
  • +

    Stack Trace:

    +
      + +
    • +
    • + 5) return "[ ".count($keys)." items ]"; + return '[ '.implode(', ', array_map(function ($item) { + return $item.' => '; + }, $keys)).']'; + case 'object': + return get_class($item); + } + }, $trace[$i]['args'])); + echo ')
    • '; + } + ?> +
    +
  • +
    - Was ist passiert? -

    Ein nicht zu korrigierender Fehler ist bei der Verarbeitung Ihrer Anfrage aufgetreten. Der interne Fehlercode lautet: {$exceptionID}

    -

    Leiten Sie diesen Code an den Administrator weiter, um ihm bei der Behebung zu helfen.

    -

    Wenn Sie der Administrator sind, dann können Sie die vollständige Fehlermeldung in der Administrationsoberfläche unter „Protokoll » Fehler“ einsehen. Der Fehlercode selbst ist für den Support wertlos!

    ]]>
    + Was ist passiert?

    +

    Leider ist bei der Verarbeitung zu einem Fehler gekommen und die Ausführung wurde abgebrochen. Falls möglich leiten Sie bitte den oben stehenden Fehlercode an den Administrator weiter.

    +

     

    +

    + Administratoren können die vollständige Fehlermeldung mit Hilfe dieses Codes in der Administrationsoberfläche unter „Protokoll » Fehler“ einsehen. + Zusätzlich wurden die Informationen in die Protokolldatei {$logFile} geschrieben und können beispielsweise mit Hilfe eines FTP-Programms abgerufen werden. +

    +

     

    +

    Hinweis: Der Fehlercode wird zufällig generiert und erlaubt keinen Rückschluss auf die Ursache und ist daher für Dritte nutzlos.

    ]]>
    + + {$exceptionID}]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index d825ff28f6..726b5ebaf4 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -2223,14 +2223,20 @@ Errors are: - What happened? -

    An unrecoverable error occured while trying to handle your request. The internal error code is as follows: {$exceptionID}

    -

    Please send this code to the administrator to help him fix the issue.

    -

    If you are the administrator you can access the full error message inside your Administration Control Panel at “Logs » Errors”. The error code itself is worthless for the support!

    ]]>
    - + What happened?

    +

    An error has occured while trying to handle your request and execution has been terminated. Please forward the above error code to the site administrator.

    +

     

    +

    + The error code can be used by an administrator to lookup the full error message in the Administration Control Panel via “Logs » Errors”. + In addition the error has been writen to the log file located at {$logFile} and can be accessed with a FTP program or similar. +

    +

     

    +

    Notice: The error code was randomly generated and has no use beyond looking up the full message.

    ]]>
    + + {$exceptionID}]]> -- 2.20.1