From 2d1e473ab8f0824231871921a9ba8e8ea992f28f Mon Sep 17 00:00:00 2001 From: magobaol Date: Tue, 18 Jun 2013 14:51:43 +0200 Subject: [PATCH 1/4] Added option 'show_error_code' --- src/php_error.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/php_error.php b/src/php_error.php index 3953ec3..6ee72d4 100644 --- a/src/php_error.php +++ b/src/php_error.php @@ -1142,6 +1142,7 @@ public static function identifyTypeHTML( $arg, $recurseLevels=1 ) { private $defaultErrorReportingOff; private $applicationRoot; private $serverName; + private $showErrorCode; private $catchClassNotFound; private $catchSurpressedErrors; @@ -1226,6 +1227,8 @@ public static function identifyTypeHTML( $arg, $recurseLevels=1 ) { * - enable_saving Can be true or false. When true, saving files is enabled, and when false, it is disabled. * Defaults to true! * + * - show_error_code Can be true or false. When true php error codes are shown in the actual error message. + * Defaults to false. * @param options Optional, an array of values to customize this handler. * @throws Exception This is raised if given an options that does *not* exist (so you know that option is meaningless). */ @@ -1268,6 +1271,7 @@ public function __construct( $options=null ) { $this->applicationRoot = ErrorHandler::optionsPop( $options, 'application_root' , $_SERVER['DOCUMENT_ROOT'] ); $this->serverName = ErrorHandler::optionsPop( $options, 'server_name' , $_SERVER['SERVER_NAME'] ); + $this->showErrorCode = ErrorHandler::optionsPop( $options, 'show_error_code' , false); /* * Relative paths might be given for document root, From 0aac492af7898a49f8c4c6f4b5acc18876a9ae38 Mon Sep 17 00:00:00 2001 From: magobaol Date: Tue, 18 Jun 2013 14:57:44 +0200 Subject: [PATCH 2/4] Added mapping of PHP Errors, mapped to descriptions of them --- src/php_error.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/php_error.php b/src/php_error.php index 6ee72d4..30f1351 100644 --- a/src/php_error.php +++ b/src/php_error.php @@ -524,6 +524,29 @@ class ErrorHandler T_UNSET => 'syntax-function' ); + /** + * A mapping of PHP errors, + * mapped to descriptions of them. + */ + private static $PHP_ERROR_MAPPINGS = array( + E_ERROR => 'E_ERROR', + E_WARNING => 'E_WARNING', + E_PARSE => 'E_PARSE', + E_NOTICE => 'E_NOTICE', + E_CORE_ERROR => 'E_CORE_ERROR', + E_CORE_WARNING => 'E_CORE_WARNING', + E_COMPILE_ERROR => 'E_COMPILE_ERROR', + E_COMPILE_WARNING => 'E_COMPILE_WARNING', + E_USER_ERROR => 'E_USER_ERROR', + E_USER_WARNING => 'E_USER_WARNING', + E_USER_NOTICE => 'E_USER_NOTICE', + E_STRICT => 'E_STRICT', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR', + E_DEPRECATED => 'E_DEPRECATED', + E_USER_DEPRECATED => 'E_USER_DEPRECATED', + E_ALL => 'E_ALL' + ); + /** * A list of methods which are known to call the autoloader, * but should not error, if the class is not found. From ee8075afaf7b3280896163c2ca9e48c363c8d0c7 Mon Sep 17 00:00:00 2001 From: magobaol Date: Tue, 18 Jun 2013 15:02:01 +0200 Subject: [PATCH 3/4] Added display logic to displayError. I needed to add a parameter (the actual error code) so I've also amended the reportError(), where displayError() is called, to pass the error code. --- src/php_error.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/php_error.php b/src/php_error.php index 30f1351..d48f1ab 100644 --- a/src/php_error.php +++ b/src/php_error.php @@ -2520,7 +2520,7 @@ public function reportError( $code, $message, $errLine, $errFile, $ex=null ) { $_SERVER ); - $this->displayError( $message, $srcErrLine, $errFile, $errFileType, $stackTrace, $fileLinesSets, $numFileLines, $dump ); + $this->displayError( $message, $srcErrLine, $errFile, $errFileType, $stackTrace, $fileLinesSets, $numFileLines, $dump, $code ); // exit in order to end processing $this->turnOff(); @@ -3251,13 +3251,15 @@ private function displayJSInjection() { * The actual display logic. * This outputs the error details in HTML. */ - private function displayError( $message, $errLine, $errFile, $errFileType, $stackTrace, &$fileLinesSets, $numFileLines, $dumpInfo ) { + private function displayError( $message, $errLine, $errFile, $errFileType, $stackTrace, &$fileLinesSets, $numFileLines, $dumpInfo, $code ) { $applicationRoot = $this->applicationRoot; $serverName = $this->serverName; $backgroundText = $this->backgroundText; $displayLineNumber = $this->displayLineNumber; $saveUrl = $this->saveUrl; $isSavingEnabled = $this->isSavingEnabled; + $showErrorCode = $this->showErrorCode; + $codeDescription = ErrorHandler::$PHP_ERROR_MAPPINGS[$code]; /* * When a query string is not provided, @@ -3294,7 +3296,10 @@ function() use ( &$fileLinesSets, $numFileLines, $displayLineNumber, $dumpInfo, - $isSavingEnabled + $isSavingEnabled, + $showErrorCode, + $code, + $codeDescription ) { if ( $backgroundText ) { ?>
@@ -3312,7 +3317,7 @@ function() use ( RETRY -

+

From 8dd14183d237025985f884eeac342d6544e6e714 Mon Sep 17 00:00:00 2001 From: magobaol Date: Tue, 18 Jun 2013 15:11:48 +0200 Subject: [PATCH 4/4] Cosmetic changes: - Added H3 css class - Added #error-code css class - Moved the error code inside an H3, shown below the error-title. --- src/php_error.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/php_error.php b/src/php_error.php index d48f1ab..5cd5fa4 100644 --- a/src/php_error.php +++ b/src/php_error.php @@ -3317,7 +3317,8 @@ function() use ( RETRY -

+

+ ".$codeDescription." (".$code.")" : ""); ?>

@@ -3629,7 +3630,8 @@ function displayHTML( Closure $head, $body=null, $javascript=null ) { } h1, - h2 { + h2, + h3 { font-family: "Segoe UI Light","Helvetica Neue",'RobotoLight',"Segoe UI","Segoe WP",sans-serif; font-weight: 100; line-height: normal; @@ -3761,6 +3763,12 @@ function displayHTML( Closure $head, $body=null, $javascript=null ) { position: relative; white-space: pre-wrap; } + + #error-code { + font-size: 14px; + margin-bottom: 0px; + margin-top: 0px; + }