ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilErrorHandling Class Reference

Error Handling & global info handling uses PEAR error class. More...

+ Inheritance diagram for ilErrorHandling:
+ Collaboration diagram for ilErrorHandling:

Public Member Functions

 ilErrorHandling ()
 Constructor public.
 getLastError ()
 errorHandler ($a_error_obj)
 defines what has to happen in case of error private
 getMessage ()
 setMessage ($a_message)
 appendMessage ($a_message)
 handleUncaughtException (Exception $e)
 Called for each uncaught exception.
 handleRuntimeErrors ($a_error_code, $a_error_message, $a_error_file, $a_error_line)
 We should enhance the error reporting in future releases (funding required).
- Public Member Functions inherited from PEAR
 PEAR ($error_class=null)
 Constructor.
 _PEAR ()
 Destructor (the emulated type of...).
getStaticProperty ($class, $var)
 If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them.
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes.
 isError ($data, $code=null)
 Tell whether a value is a PEAR error.
 setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled.
 expectError ($code= '*')
 This method is used to tell which errors you expect to get.
 popExpect ()
 This method pops one element off the expected error codes stack.
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available.
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack.
raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
 This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied.
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options.
 staticPushErrorHandling ($mode, $options=null)
 staticPopErrorHandling ()
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack.
 popErrorHandling ()
 Pop the last error handler used.
 loadExtension ($ext)
 OS independant PHP extension load.

Static Public Member Functions

static _ilErrorWriter ($errno, $errstr, $errfile, $errline)
 This is used in Soap calls to write PHP error in ILIAS Logfile Not used yet!!!

Data Fields

 $DEBUG_ENV
 $FATAL
 $WARNING
 $MESSAGE
- Data Fields inherited from PEAR
 $_debug = false
 $_default_error_mode = null
 $_default_error_options = null
 $_default_error_handler = ''
 $_error_class = 'PEAR_Error'
 $_expected_errors = array()

Protected Member Functions

 formatBacktraceArray (array $a_backtrace)
 translateErrorCode ($error_code)
 Translates an integer error code to the corresponding error string.

Detailed Description

Error Handling & global info handling uses PEAR error class.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Sascha Hofmann shofm.nosp@m.ann@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
Id:
class.ilErrorHandling.php 58459 2015-03-17 15:41:20Z gitmgr
Todo:
when an error occured and clicking the back button to return to previous page the referer-var in session is deleted -> server error

Definition at line 18 of file class.ilErrorHandling.php.

Member Function Documentation

static ilErrorHandling::_ilErrorWriter (   $errno,
  $errstr,
  $errfile,
  $errline 
)
static

This is used in Soap calls to write PHP error in ILIAS Logfile Not used yet!!!

public

Parameters

Definition at line 237 of file class.ilErrorHandling.php.

References $ilLog, and exit.

{
global $ilLog;
switch($errno)
{
case E_USER_ERROR:
$ilLog->write('PHP errror: '.$errstr.'. FATAL error on line '.$errline.' in file '.$errfile);
unset($ilLog);
exit(1);
case E_USER_WARNING:
$ilLog->write('PHP warning: ['.$errno.'] '.$errstr.' on line '.$errline.' in file '.$errfile);
break;
}
return true;
}
ilErrorHandling::appendMessage (   $a_message)

Definition at line 219 of file class.ilErrorHandling.php.

References getMessage().

{
if($this->getMessage())
{
$this->message .= "<br /> ";
}
$this->message .= $a_message;
}

+ Here is the call graph for this function:

ilErrorHandling::errorHandler (   $a_error_obj)

defines what has to happen in case of error private

Parameters
objectError

Definition at line 85 of file class.ilErrorHandling.php.

References $_POST, $_SESSION, $FATAL, $log, $MESSAGE, $WARNING, exit, and ilUtil\redirect().

{
global $log;
$this->error_obj =& $a_error_obj;
//echo "-".$_SESSION["referer"]."-";
if ($_SESSION["failure"] && substr($a_error_obj->getMessage(), 0, 22) != "Cannot find this block")
{
$m = "Fatal Error: Called raise error two times.<br>".
"First error: ".$_SESSION["failure"].'<br>'.
"Last Error:". $a_error_obj->getMessage();
//return;
$log->logError($a_error_obj->getCode(), $m);
unset($_SESSION["failure"]);
die ($m);
}
if (substr($a_error_obj->getMessage(), 0, 22) == "Cannot find this block")
{
if (DEVMODE == 1)
{
echo "<b>DEVMODE</b><br><br>";
echo "<b>Template Block not found.</b><br>";
echo "You used a template block in your code that is not available.<br>";
echo "Native Messge: <b>".$a_error_obj->getMessage()."</b><br>";
if (is_array($a_error_obj->backtrace))
{
echo "Backtrace:<br>";
foreach ($a_error_obj->backtrace as $b)
{
if ($b["function"] == "setCurrentBlock" &&
basename($b["file"]) != "class.ilTemplate.php")
{
echo "<b>";
}
echo "File: ".$b["file"].", ";
echo "Line: ".$b["line"].", ";
echo $b["function"]."()<br>";
if ($b["function"] == "setCurrentBlock" &&
basename($b["file"]) != "class.ilTemplate.php")
{
echo "</b>";
}
}
}
}
return;
}
if (is_object($log) and $log->enabled == true)
{
$log->logError($a_error_obj->getCode(),$a_error_obj->getMessage());
}
//echo $a_error_obj->getCode().":"; exit;
if ($a_error_obj->getCode() == $this->FATAL)
{
trigger_error(stripslashes($a_error_obj->getMessage()), E_USER_ERROR);
exit();
}
if ($a_error_obj->getCode() == $this->WARNING)
{
if ($this->DEBUG_ENV)
{
$message = $a_error_obj->getMessage();
}
else
{
$message = "Under Construction";
}
$_SESSION["failure"] = $message;
if (!defined("ILIAS_MODULE"))
{
ilUtil::redirect("error.php");
}
else
{
ilUtil::redirect("../error.php");
}
}
if ($a_error_obj->getCode() == $this->MESSAGE)
{
$_SESSION["failure"] = $a_error_obj->getMessage();
// save post vars to session in case of error
$_SESSION["error_post_vars"] = $_POST;
if (empty($_SESSION["referer"]))
{
$dirname = dirname($_SERVER["PHP_SELF"]);
$ilurl = parse_url(ILIAS_HTTP_PATH);
$subdir = substr(strstr($dirname,$ilurl["path"]),strlen($ilurl["path"]));
$updir = "";
if ($subdir)
{
$num_subdirs = substr_count($subdir,"/");
for ($i=1;$i<=$num_subdirs;$i++)
{
$updir .= "../";
}
}
ilUtil::redirect($updir."index.php");
}
/* #12104
check if already GET-Parameters exists in Referer-URI
if (substr($_SESSION["referer"],-4) == ".php")
{
$glue = "?";
}
else
{
// this did break permanent links (".html&")
$glue = "&";
}
*/
}
}

+ Here is the call graph for this function:

ilErrorHandling::formatBacktraceArray ( array  $a_backtrace)
protected
Parameters
array$a_backtrace
Returns
array

Definition at line 310 of file class.ilErrorHandling.php.

Referenced by handleRuntimeErrors().

{
$stack = array();
$i = 1;
unset($a_backtrace[0]); // remove first call from stack trace
foreach($a_backtrace as $item)
{
$stack_line = "#$i " . $item['file'] . "(" . $item['line'] . "): ";
if(isset($item['class']))
{
$stack_line .= $item['class'] . "->";
}
$stack_line .= $item['function'] . "()";
array_push($stack, $stack_line);
$i++;
}
return $stack;
}

+ Here is the caller graph for this function:

ilErrorHandling::getLastError ( )

Definition at line 75 of file class.ilErrorHandling.php.

{
return $this->error_obj;
}
ilErrorHandling::getMessage ( )

Definition at line 211 of file class.ilErrorHandling.php.

Referenced by appendMessage().

{
return $this->message;
}

+ Here is the caller graph for this function:

ilErrorHandling::handleRuntimeErrors (   $a_error_code,
  $a_error_message,
  $a_error_file,
  $a_error_line 
)

We should enhance the error reporting in future releases (funding required).

Idea: We should convert php errors to exceptions and tweak the exception handling (already enhanced by smeyer in former releases) We should implement handlers depending on the context (web/html, soap/xml, rest/json, cli/plain text, ...)

Parameters
int$a_error_code
string$a_error_message
string$a_error_file
int$a_error_line
Returns
mixed The error handler must return FALSE to populate

Definition at line 282 of file class.ilErrorHandling.php.

References formatBacktraceArray(), ilRuntime\getInstance(), and translateErrorCode().

{
// #15641 - the silence operator should suppress the error completely
if(error_reporting() === 0)
{
return;
}
$backtrace_array = $this->formatBacktraceArray(debug_backtrace());
$error_code = $this->translateErrorCode($a_error_code);
if(ilRuntime::getInstance()->shouldLogErrors())
{
error_log($error_code . ': ' . $a_error_message . ' in '.$a_error_file . ' on line ' . $a_error_line . PHP_EOL . implode(PHP_EOL, $backtrace_array));
}
if(ilRuntime::getInstance()->shouldDisplayErrors())
{
print '<br /><b>' . $error_code . '</b>: ' . $a_error_message . ' in <b>'.$a_error_file . '</b> on line <b>' . $a_error_line . '</b><br/>' . implode('<br />', $backtrace_array);
}
return true;
}

+ Here is the call graph for this function:

ilErrorHandling::handleUncaughtException ( Exception  $e)

Called for each uncaught exception.

Parameters
Exception$e

Definition at line 260 of file class.ilErrorHandling.php.

References PEAR\raiseError().

{
$error = $e->getMessage();
if (DEVMODE)
{
$error.= '<br /><br />';
$error.= nl2br($e->getTraceAsString());
}
$this->raiseError($error,$this->WARNING);
}

+ Here is the call graph for this function:

ilErrorHandling::ilErrorHandling ( )

Constructor public.

Definition at line 52 of file class.ilErrorHandling.php.

References ilRuntime\getInstance(), and PEAR\PEAR().

{
$this->PEAR();
// init vars
$this->DEBUG_ENV = true;
$this->FATAL = 1;
$this->WARNING = 2;
$this->MESSAGE = 3;
$this->error_obj = false;
// Runtime errors currently only handled for HHVM
if(ilRuntime::getInstance()->isHHVM())
{
set_error_handler(
array($this, 'handleRuntimeErrors'),
ilRuntime::getInstance()->getReportedErrorLevels()
);
}
set_exception_handler(array($this, 'handleUncaughtException'));
}

+ Here is the call graph for this function:

ilErrorHandling::setMessage (   $a_message)

Definition at line 215 of file class.ilErrorHandling.php.

{
$this->message = $a_message;
}
ilErrorHandling::translateErrorCode (   $error_code)
protected

Translates an integer error code to the corresponding error string.

Parameters
int$error_code
Returns
string

Definition at line 336 of file class.ilErrorHandling.php.

Referenced by handleRuntimeErrors().

{
$constants = get_defined_constants(true);
foreach($constants['Core'] as $constant => $value)
{
if(substr($constant, 0, 2) == 'E_' && $value == $error_code)
{
return $constant;
}
}
return 'E_UNKNOWN';
}

+ Here is the caller graph for this function:

Field Documentation

ilErrorHandling::$DEBUG_ENV

Definition at line 25 of file class.ilErrorHandling.php.

ilErrorHandling::$FATAL

Definition at line 32 of file class.ilErrorHandling.php.

Referenced by errorHandler().

ilErrorHandling::$MESSAGE

Definition at line 46 of file class.ilErrorHandling.php.

Referenced by errorHandler().

ilErrorHandling::$WARNING

Definition at line 39 of file class.ilErrorHandling.php.

Referenced by errorHandler().


The documentation for this class was generated from the following file: