ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilErrorHandling Class Reference
+ Inheritance diagram for ilErrorHandling:
+ Collaboration diagram for ilErrorHandling:

Public Member Functions

 ilErrorHandling ()
 Constructor public. More...
 
 getHandler ()
 Get a handler for an error or exception. More...
 
 getLastError ()
 
 errorHandler ($a_error_obj)
 defines what has to happen in case of error private More...
 
 getMessage ()
 
 setMessage ($a_message)
 
 appendMessage ($a_message)
 
 logMessageFor (Exception $exception, $log_trace)
 Get the error message to be logged. 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

 initHandlers ()
 Initialize Error and Exception Handlers. More...
 
 getIlRuntime ()
 Get ilRuntime. More...
 
 getWhoops ()
 Get an instance of Whoops/Run. More...
 
 isDevmodeActive ()
 Is the DEVMODE switched on? More...
 
 defaultHandler ()
 Get a default error handler. More...
 
 devmodeHandler ()
 Get the handler to be used in DEVMODE. More...
 

Static Protected Attributes

static $handlers_registered = false
 

Detailed Description

Definition at line 45 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 320 of file class.ilErrorHandling.php.

References $ilLog, and exit.

321  {
322  global $ilLog;
323 
324  switch($errno)
325  {
326  case E_USER_ERROR:
327  $ilLog->write('PHP errror: '.$errstr.'. FATAL error on line '.$errline.' in file '.$errfile);
328  unset($ilLog);
329  exit(1);
330 
331  case E_USER_WARNING:
332  $ilLog->write('PHP warning: ['.$errno.'] '.$errstr.' on line '.$errline.' in file '.$errfile);
333  break;
334 
335  }
336  return true;
337  }
exit
Definition: login.php:54

◆ appendMessage()

ilErrorHandling::appendMessage (   $a_message)

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

References getMessage().

303  {
304  if($this->getMessage())
305  {
306  $this->message .= "<br /> ";
307  }
308  $this->message .= $a_message;
309  }
+ Here is the call graph for this function:

◆ defaultHandler()

ilErrorHandling::defaultHandler ( )
protected

Get a default error handler.

Returns
Whoops

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

References $_SESSION, $lng, $tpl, exit, ilUtil\redirect(), and ilUtil\sendFailure().

Referenced by getHandler().

367  {
368  return new CallbackHandler(function(Exception $exception, Inspector $inspector, Run $run) {
369  if ($exception instanceof \Whoops\Exception\ErrorException
370  and $exception->getCode() == E_ERROR) {
371  global $tpl, $lng, $tree;
372  $_SESSION["failure"] = $exception->getMessage();
373  include("error.php");
374  exit();
375  }
376 
377  require_once("Services/Utilities/classes/class.ilUtil.php");
378  ilUtil::sendFailure($exception->getMessage(), true);
379  // many test installation have display_errors on, we do not need additional information in this case
380  // however in cases of warnings, whoops seems to get rid of these messages, but not in the case of fatals
381  // so we do not check for ini_get("display_errors"), but for headers_sent()
382  if (!headers_sent())
383  {
384  // #0019268, when not in setup
385  if (class_exists("ilInitialisation"))
386  {
387  ilInitialisation::initHTML();
388  global $tpl, $lng, $tree;
389  include("error.php"); // redirect will not display fatal error messages, since writing to session (sendFailure) will not work at this point
390  }
391  else // when in setup...
392  {
393  ilUtil::redirect("error.php");
394  }
395  }
396  });
397  }
exit
Definition: login.php:54
$_SESSION["AccountId"]
global $tpl
Definition: ilias.php:8
Whoops - php errors for cool kids.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $lng
Definition: privfeed.php:40
Wrapper for Closures passed as handlers.
static redirect($a_script)
http redirect to other script
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ devmodeHandler()

ilErrorHandling::devmodeHandler ( )
protected

Get the handler to be used in DEVMODE.

Returns
Whoops

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

References $ilLog, and Monolog\Handler\error_log().

Referenced by getHandler().

403  {
404  global $ilLog;
405 
406  switch (ERROR_HANDLER) {
407  case "TESTING":
408  return new ilTestingHandler();
409  case "PLAIN_TEXT":
410  return new ilPlainTextHandler();
411  case "PRETTY_PAGE":
412  return new PrettyPageHandler();
413  default:
414  if ($ilLog) {
415  $ilLog->write("Unknown or undefined error handler '".ERROR_HANDLER."'. "
416  ."Falling back to PrettyPageHandler.");
417  }
418  return new PrettyPageHandler();
419  }
420  }
A Whoops error handler for testing.
+ Here is the call graph for this function:
+ Here is the caller 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 158 of file class.ilErrorHandling.php.

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

159  {
160  global $log;
161 
162  // see bug 18499 (some calls to raiseError do not pass a code, which leads to security issues, if these calls
163  // are done due to permission checks)
164  if ($a_error_obj->getCode() == null)
165  {
166  $a_error_obj->code = $this->WARNING;
167  }
168 
169  $this->error_obj =& $a_error_obj;
170 //echo "-".$_SESSION["referer"]."-";
171  if ($_SESSION["failure"] && substr($a_error_obj->getMessage(), 0, 22) != "Cannot find this block")
172  {
173  $m = "Fatal Error: Called raise error two times.<br>".
174  "First error: ".$_SESSION["failure"].'<br>'.
175  "Last Error:". $a_error_obj->getMessage();
176  //return;
177  $log->write($m);
178  #$log->writeWarning($m);
179  #$log->logError($a_error_obj->getCode(), $m);
180  unset($_SESSION["failure"]);
181  die ($m);
182  }
183 
184  if (substr($a_error_obj->getMessage(), 0, 22) == "Cannot find this block")
185  {
186  if (DEVMODE == 1)
187  {
188  echo "<b>DEVMODE</b><br><br>";
189  echo "<b>Template Block not found.</b><br>";
190  echo "You used a template block in your code that is not available.<br>";
191  echo "Native Messge: <b>".$a_error_obj->getMessage()."</b><br>";
192  if (is_array($a_error_obj->backtrace))
193  {
194  echo "Backtrace:<br>";
195  foreach ($a_error_obj->backtrace as $b)
196  {
197  if ($b["function"] == "setCurrentBlock" &&
198  basename($b["file"]) != "class.ilTemplate.php")
199  {
200  echo "<b>";
201  }
202  echo "File: ".$b["file"].", ";
203  echo "Line: ".$b["line"].", ";
204  echo $b["function"]."()<br>";
205  if ($b["function"] == "setCurrentBlock" &&
206  basename($b["file"]) != "class.ilTemplate.php")
207  {
208  echo "</b>";
209  }
210  }
211  }
212  exit;
213  }
214  return;
215  }
216 
217  if (is_object($log) and $log->enabled == true)
218  {
219  $log->write($a_error_obj->getMessage());
220  #$log->logError($a_error_obj->getCode(),$a_error_obj->getMessage());
221  }
222 
223 //echo $a_error_obj->getCode().":"; exit;
224  if ($a_error_obj->getCode() == $this->FATAL)
225  {
226  trigger_error(stripslashes($a_error_obj->getMessage()), E_USER_ERROR);
227  exit();
228  }
229 
230  if ($a_error_obj->getCode() == $this->WARNING)
231  {
232  if ($this->DEBUG_ENV)
233  {
234  $message = $a_error_obj->getMessage();
235  }
236  else
237  {
238  $message = "Under Construction";
239  }
240 
241  $_SESSION["failure"] = $message;
242 
243  if (!defined("ILIAS_MODULE"))
244  {
245  ilUtil::redirect("error.php");
246  }
247  else
248  {
249  ilUtil::redirect("../error.php");
250  }
251  }
252 
253  if ($a_error_obj->getCode() == $this->MESSAGE)
254  {
255  $_SESSION["failure"] = $a_error_obj->getMessage();
256  // save post vars to session in case of error
257  $_SESSION["error_post_vars"] = $_POST;
258 
259  if (empty($_SESSION["referer"]))
260  {
261  $dirname = dirname($_SERVER["PHP_SELF"]);
262  $ilurl = parse_url(ILIAS_HTTP_PATH);
263  $subdir = substr(strstr($dirname,$ilurl["path"]),strlen($ilurl["path"]));
264  $updir = "";
265 
266  if ($subdir)
267  {
268  $num_subdirs = substr_count($subdir,"/");
269 
270  for ($i=1;$i<=$num_subdirs;$i++)
271  {
272  $updir .= "../";
273  }
274  }
275  ilUtil::redirect($updir."index.php");
276  }
277 
278  /* #12104
279  check if already GET-Parameters exists in Referer-URI
280  if (substr($_SESSION["referer"],-4) == ".php")
281  {
282  $glue = "?";
283  }
284  else
285  {
286  // this did break permanent links (".html&")
287  $glue = "&";
288  }
289  */
290  ilUtil::redirect($_SESSION["referer"]);
291  }
292  }
exit
Definition: login.php:54
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$_POST['username']
Definition: cron.php:12
$_SESSION["AccountId"]
static redirect($a_script)
http redirect to other script
+ Here is the call graph for this function:

◆ getHandler()

ilErrorHandling::getHandler ( )

Get a handler for an error or exception.

Uses Whoops Pretty Page Handler in DEVMODE and the legacy ILIAS-Error handlers otherwise.

Returns
Whoops

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

References defaultHandler(), devmodeHandler(), and isDevmodeActive().

135  {
136  // TODO: * Use Whoops in production mode? This would require an appropriate
137  // error-handler.
138  // * Check for context? The current implementation e.g. would output HTML for
139  // for SOAP.
140 
141  if ($this->isDevmodeActive()) {
142  return $this->devmodeHandler();
143  }
144 
145  return $this->defaultHandler();
146  }
isDevmodeActive()
Is the DEVMODE switched on?
defaultHandler()
Get a default error handler.
devmodeHandler()
Get the handler to be used in DEVMODE.
+ Here is the call graph for this function:

◆ getIlRuntime()

ilErrorHandling::getIlRuntime ( )
protected

Get ilRuntime.

Returns
ilRuntime

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

References ilRuntime\getInstance().

Referenced by initHandlers().

343  {
344  return ilRuntime::getInstance();
345  }
static getInstance()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLastError()

ilErrorHandling::getLastError ( )

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

149  {
150  return $this->error_obj;
151  }

◆ getMessage()

ilErrorHandling::getMessage ( )

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

Referenced by appendMessage().

295  {
296  return $this->message;
297  }
+ Here is the caller graph for this function:

◆ getWhoops()

ilErrorHandling::getWhoops ( )
protected

Get an instance of Whoops/Run.

Returns
Whoops

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

Referenced by initHandlers().

351  {
352  return new Run();
353  }
+ Here is the caller graph for this function:

◆ ilErrorHandling()

ilErrorHandling::ilErrorHandling ( )

Constructor public.

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

References initHandlers(), and PEAR\PEAR().

86  {
87  $this->PEAR();
88 
89  // init vars
90  $this->DEBUG_ENV = true;
91  $this->FATAL = 1;
92  $this->WARNING = 2;
93  $this->MESSAGE = 3;
94 
95  $this->error_obj = false;
96 
97  $this->initHandlers();
98  }
initHandlers()
Initialize Error and Exception Handlers.
PEAR($error_class=null)
Constructor.
Definition: PEAR.php:170
+ Here is the call graph for this function:

◆ initHandlers()

ilErrorHandling::initHandlers ( )
protected

Initialize Error and Exception Handlers.

Initializes Whoops, a logging handler and a delegate handler for the late initialisation of an appropriate error handler.

Returns
void

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

References getIlRuntime(), and getWhoops().

Referenced by ilErrorHandling().

108  {
109  if (self::$handlers_registered) {
110  // Only register whoops error handlers once.
111  return;
112  }
113 
114  $ilRuntime = $this->getIlRuntime();
115  $whoops = $this->getWhoops();
116 
117  $whoops->pushHandler(new ilDelegatingHandler($this));
118 
119  if ($ilRuntime->shouldLogErrors()) {
120  $whoops->pushHandler($this->loggingHandler());
121  }
122 
123  $whoops->register();
124 
125  self::$handlers_registered = true;
126  }
getWhoops()
Get an instance of Whoops/Run.
getIlRuntime()
Get ilRuntime.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isDevmodeActive()

ilErrorHandling::isDevmodeActive ( )
protected

Is the DEVMODE switched on?

Returns
bool

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

Referenced by getHandler().

359  {
360  return DEVMODE == 1;
361  }
+ Here is the caller graph for this function:

◆ logMessageFor()

ilErrorHandling::logMessageFor ( Exception  $exception,
  $log_trace 
)

Get the error message to be logged.

TODO: Can be made protected when support for PHP 5.3. is dropped.

Parameters
$exceptionException
$log_tracebool
Returns
string

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

457  {
458  assert('is_bool($log_trace)');
459  $prefix = "PHP Error: ";
460  if ($exception instanceof \Whoops\Exception\ErrorException) {
461  switch ($exception->getCode()) {
462  case E_ERROR:
463  case E_USER_ERROR:
464  $prefix = "PHP Fatal error: ";
465  }
466  }
467 
468  $msg = $prefix.$exception->getMessage()." in ".$exception->getFile()." on line ".$exception->getLine();
469 
470  if ($log_trace) {
471  $msg .= "\n".$exception->getTraceAsString();
472  }
473 
474  return $msg;
475  }
Whoops - php errors for cool kids.

◆ setMessage()

ilErrorHandling::setMessage (   $a_message)

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

299  {
300  $this->message = $a_message;
301  }

Field Documentation

◆ $DEBUG_ENV

ilErrorHandling::$DEBUG_ENV

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

◆ $FATAL

ilErrorHandling::$FATAL

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

Referenced by errorHandler().

◆ $handlers_registered

ilErrorHandling::$handlers_registered = false
staticprotected

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

◆ $MESSAGE

ilErrorHandling::$MESSAGE

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

Referenced by errorHandler().

◆ $WARNING

ilErrorHandling::$WARNING

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

Referenced by errorHandler().


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