ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules 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. More...
 
 getLastError ()
 
 errorHandler ($a_error_obj)
 defines what has to happen in case of error private More...
 
 getMessage ()
 
 setMessage ($a_message)
 
 appendMessage ($a_message)
 
 handleUncaughtException (Exception $e)
 Called for each uncaught exception. More...
 
 handleRuntimeErrors ($a_error_code, $a_error_message, $a_error_file, $a_error_line)
 We should enhance the error reporting in future releases (funding required). More...
 
- Public Member Functions inherited from PEAR
 PEAR ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). More...
 
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. More...
 
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes. More...
 
 isError ($data, $code=null)
 Tell whether a value is a PEAR error. More...
 
 setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. More...
 
 expectError ($code=' *')
 This method is used to tell which errors you expect to get. More...
 
 popExpect ()
 This method pops one element off the expected error codes stack. More...
 
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available. More...
 
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack. More...
 
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. More...
 
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options. More...
 
 staticPushErrorHandling ($mode, $options=null)
 
 staticPopErrorHandling ()
 
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack. More...
 
 popErrorHandling ()
 Pop the last error handler used. More...
 
 loadExtension ($ext)
 OS independant PHP extension load. More...
 

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!!! More...
 

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. More...
 

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$
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

◆ _ilErrorWriter()

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 244 of file class.ilErrorHandling.php.

References $ilLog, and exit.

245  {
246  global $ilLog;
247 
248  switch($errno)
249  {
250  case E_USER_ERROR:
251  $ilLog->write('PHP errror: '.$errstr.'. FATAL error on line '.$errline.' in file '.$errfile);
252  unset($ilLog);
253  exit(1);
254 
255  case E_USER_WARNING:
256  $ilLog->write('PHP warning: ['.$errno.'] '.$errstr.' on line '.$errline.' in file '.$errfile);
257  break;
258 
259  }
260  return true;
261  }
exit
Definition: login.php:54

◆ appendMessage()

ilErrorHandling::appendMessage (   $a_message)

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

References getMessage().

227  {
228  if($this->getMessage())
229  {
230  $this->message .= "<br /> ";
231  }
232  $this->message .= $a_message;
233  }
+ Here is the call graph for this function:

◆ errorHandler()

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().

86  {
87  global $log;
88 
89  // see bug 18499 (some calls to raiseError do not pass a code, which leads to security issues, if these calls
90  // are done due to permission checks)
91  if ($a_error_obj->getCode() == null)
92  {
93  $a_error_obj->code = $this->WARNING;
94  }
95 
96  $this->error_obj =& $a_error_obj;
97 //echo "-".$_SESSION["referer"]."-";
98  if ($_SESSION["failure"] && substr($a_error_obj->getMessage(), 0, 22) != "Cannot find this block")
99  {
100  $m = "Fatal Error: Called raise error two times.<br>".
101  "First error: ".$_SESSION["failure"].'<br>'.
102  "Last Error:". $a_error_obj->getMessage();
103  //return;
104  $log->logError($a_error_obj->getCode(), $m);
105  unset($_SESSION["failure"]);
106  die ($m);
107  }
108 
109  if (substr($a_error_obj->getMessage(), 0, 22) == "Cannot find this block")
110  {
111  if (DEVMODE == 1)
112  {
113  echo "<b>DEVMODE</b><br><br>";
114  echo "<b>Template Block not found.</b><br>";
115  echo "You used a template block in your code that is not available.<br>";
116  echo "Native Messge: <b>".$a_error_obj->getMessage()."</b><br>";
117  if (is_array($a_error_obj->backtrace))
118  {
119  echo "Backtrace:<br>";
120  foreach ($a_error_obj->backtrace as $b)
121  {
122  if ($b["function"] == "setCurrentBlock" &&
123  basename($b["file"]) != "class.ilTemplate.php")
124  {
125  echo "<b>";
126  }
127  echo "File: ".$b["file"].", ";
128  echo "Line: ".$b["line"].", ";
129  echo $b["function"]."()<br>";
130  if ($b["function"] == "setCurrentBlock" &&
131  basename($b["file"]) != "class.ilTemplate.php")
132  {
133  echo "</b>";
134  }
135  }
136  }
137  exit;
138  }
139  return;
140  }
141 
142  if (is_object($log) and $log->enabled == true)
143  {
144  $log->logError($a_error_obj->getCode(),$a_error_obj->getMessage());
145  }
146 
147 //echo $a_error_obj->getCode().":"; exit;
148  if ($a_error_obj->getCode() == $this->FATAL)
149  {
150  trigger_error(stripslashes($a_error_obj->getMessage()), E_USER_ERROR);
151  exit();
152  }
153 
154  if ($a_error_obj->getCode() == $this->WARNING)
155  {
156  if ($this->DEBUG_ENV)
157  {
158  $message = $a_error_obj->getMessage();
159  }
160  else
161  {
162  $message = "Under Construction";
163  }
164 
165  $_SESSION["failure"] = $message;
166 
167  if (!defined("ILIAS_MODULE"))
168  {
169  ilUtil::redirect("error.php");
170  }
171  else
172  {
173  ilUtil::redirect("../error.php");
174  }
175  }
176 
177  if ($a_error_obj->getCode() == $this->MESSAGE)
178  {
179  $_SESSION["failure"] = $a_error_obj->getMessage();
180  // save post vars to session in case of error
181  $_SESSION["error_post_vars"] = $_POST;
182 
183  if (empty($_SESSION["referer"]))
184  {
185  $dirname = dirname($_SERVER["PHP_SELF"]);
186  $ilurl = parse_url(ILIAS_HTTP_PATH);
187  $subdir = substr(strstr($dirname,$ilurl["path"]),strlen($ilurl["path"]));
188  $updir = "";
189 
190  if ($subdir)
191  {
192  $num_subdirs = substr_count($subdir,"/");
193 
194  for ($i=1;$i<=$num_subdirs;$i++)
195  {
196  $updir .= "../";
197  }
198  }
199  ilUtil::redirect($updir."index.php");
200  }
201 
202  /* #12104
203  check if already GET-Parameters exists in Referer-URI
204  if (substr($_SESSION["referer"],-4) == ".php")
205  {
206  $glue = "?";
207  }
208  else
209  {
210  // this did break permanent links (".html&")
211  $glue = "&";
212  }
213  */
214  ilUtil::redirect($_SESSION["referer"]);
215  }
216  }
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
exit
Definition: login.php:54
$_POST['username']
Definition: cron.php:12
static redirect($a_script)
http redirect to other script
+ Here is the call graph for this function:

◆ formatBacktraceArray()

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

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

Referenced by handleRuntimeErrors().

318  {
319  $stack = array();
320  $i = 1;
321 
322  unset($a_backtrace[0]); // remove first call from stack trace
323  foreach($a_backtrace as $item)
324  {
325  $stack_line = "#$i " . $item['file'] . "(" . $item['line'] . "): ";
326  if(isset($item['class']))
327  {
328  $stack_line .= $item['class'] . "->";
329  }
330  $stack_line .= $item['function'] . "()";
331  array_push($stack, $stack_line);
332  $i++;
333  }
334 
335  return $stack;
336  }
+ Here is the caller graph for this function:

◆ getLastError()

ilErrorHandling::getLastError ( )

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

76  {
77  return $this->error_obj;
78  }

◆ getMessage()

ilErrorHandling::getMessage ( )

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

Referenced by appendMessage().

219  {
220  return $this->message;
221  }
+ Here is the caller graph for this function:

◆ handleRuntimeErrors()

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 289 of file class.ilErrorHandling.php.

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

290  {
291  // #15641 - the silence operator should suppress the error completely
292  if(error_reporting() === 0)
293  {
294  return;
295  }
296 
297  $backtrace_array = $this->formatBacktraceArray(debug_backtrace());
298  $error_code = $this->translateErrorCode($a_error_code);
299 
300  if(ilRuntime::getInstance()->shouldLogErrors())
301  {
302  error_log($error_code . ': ' . $a_error_message . ' in '.$a_error_file . ' on line ' . $a_error_line . PHP_EOL . implode(PHP_EOL, $backtrace_array));
303  }
304 
305  if(ilRuntime::getInstance()->shouldDisplayErrors())
306  {
307  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);
308  }
309 
310  return true;
311  }
static getInstance()
formatBacktraceArray(array $a_backtrace)
translateErrorCode($error_code)
Translates an integer error code to the corresponding error string.
+ Here is the call graph for this function:

◆ handleUncaughtException()

ilErrorHandling::handleUncaughtException ( Exception  $e)

Called for each uncaught exception.

Parameters
Exception$e

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

References PEAR\raiseError().

268  {
269  $error = $e->getMessage();
270  if (DEVMODE)
271  {
272  $error.= '<br /><br />';
273  $error.= nl2br($e->getTraceAsString());
274  }
275  $this->raiseError($error,$this->WARNING);
276  }
& 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&#39;s de...
Definition: PEAR.php:524
+ Here is the call graph for this function:

◆ ilErrorHandling()

ilErrorHandling::ilErrorHandling ( )

Constructor public.

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

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

53  {
54  $this->PEAR();
55 
56  // init vars
57  $this->DEBUG_ENV = true;
58  $this->FATAL = 1;
59  $this->WARNING = 2;
60  $this->MESSAGE = 3;
61 
62  $this->error_obj = false;
63 
64  // Runtime errors currently only handled for HHVM
65  if(ilRuntime::getInstance()->isHHVM())
66  {
67  set_error_handler(
68  array($this, 'handleRuntimeErrors'),
69  ilRuntime::getInstance()->getReportedErrorLevels()
70  );
71  }
72  set_exception_handler(array($this, 'handleUncaughtException'));
73  }
static getInstance()
PEAR($error_class=null)
Constructor.
Definition: PEAR.php:170
+ Here is the call graph for this function:

◆ setMessage()

ilErrorHandling::setMessage (   $a_message)

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

223  {
224  $this->message = $a_message;
225  }

◆ translateErrorCode()

ilErrorHandling::translateErrorCode (   $error_code)
protected

Translates an integer error code to the corresponding error string.

Parameters
int$error_code
Returns
string

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

Referenced by handleRuntimeErrors().

344  {
345  $constants = get_defined_constants(true);
346  foreach($constants['Core'] as $constant => $value)
347  {
348  if(substr($constant, 0, 2) == 'E_' && $value == $error_code)
349  {
350  return $constant;
351  }
352  }
353 
354  return 'E_UNKNOWN';
355  }
+ Here is the caller graph for this function:

Field Documentation

◆ $DEBUG_ENV

ilErrorHandling::$DEBUG_ENV

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

◆ $FATAL

ilErrorHandling::$FATAL

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

Referenced by errorHandler().

◆ $MESSAGE

ilErrorHandling::$MESSAGE

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

Referenced by errorHandler().

◆ $WARNING

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: