summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/errors/error_general.php5
-rw-r--r--index.php55
2 files changed, 59 insertions, 1 deletions
diff --git a/application/errors/error_general.php b/application/errors/error_general.php
index be495e4f6..844dfb74d 100644
--- a/application/errors/error_general.php
+++ b/application/errors/error_general.php
@@ -43,6 +43,9 @@ if (class_exists("CI_Controller") && !isset($GLOBALS["is_error_page"])) {
<?php
include 'application/views/footer.php';
+} elseif (php_sapi_name() === 'cli' OR defined('STDIN')) {
+ echo "$heading\n";
+ echo str_replace("<br>", "\n", $message);
} else {
// default CI error page
?>
@@ -96,7 +99,7 @@ code {
-webkit-box-shadow: 0 0 8px #D0D0D0;
}
-p {
+p, div {
margin: 12px 15px 12px 15px;
}
</style>
diff --git a/index.php b/index.php
index 2bf26537b..00ab370c3 100644
--- a/index.php
+++ b/index.php
@@ -196,6 +196,61 @@ if (false && defined('ENVIRONMENT'))
}
/*
+ * Custom error handling
+ */
+/* CI uses that name for it's error handling function. It misleading, but
+ * whatever. If I don't use it the framework will override my handler later.
+ */
+function _exception_handler($errno, $errstr, $errfile, $errline)
+{
+ if (!(error_reporting() & $errno)) {
+ // This error code is not included in error_reporting
+ return;
+ }
+ throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
+}
+set_error_handler("_exception_handler");
+
+// The actual exception handler
+function _actual_exception_handler($e)
+{
+ $display_errors = in_array(strtolower(ini_get('display_errors')), array('1', 'on', 'true', 'stdout'));
+
+ $GLOBALS["is_error_page"] = true;
+ $heading = "Internal Server Error";
+ $message = "<p>An unhandled error occured.</p>\n";
+ if ($display_errors) {
+ $message .= '<div>';
+ $message .= '<b>Fatal error</b>: Uncaught exception '.get_class($e).'<br>';
+ $message .= '<b>Message</b>: '.$e->getMessage().'<br>';
+ $message .= '<pre>'.(str_replace(FCPATH, "./", $e->getTraceAsString())).'</pre>';
+ $message .= 'thrown in <b>'.$e->getFile().'</b> on line <b>'.$e->getLine().'</b><br>';
+ $message .= '</div>';
+ } else {
+ $message .="<p>More information can be found in syslog or by enabling display_errors.</p>";
+ }
+
+ error_log($e);
+
+ $message = "$message";
+ include APPPATH."/errors/error_general.php";
+}
+set_exception_handler('_actual_exception_handler');
+
+/**
+ * Checks for a fatal error, work around for set_error_handler not working on fatal errors.
+ */
+function check_for_fatal()
+{
+ $error = error_get_last();
+ if ($error["type"] == E_ERROR) {
+ _actual_exception_handler(new ErrorException(
+ $error["message"], 0, $error["type"], $error["file"], $error["line"]));
+ }
+}
+register_shutdown_function("check_for_fatal");
+
+/*
* --------------------------------------------------------------------
* LOAD THE BOOTSTRAP FILE
* --------------------------------------------------------------------