ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilErrorHandling Class Reference
+ Inheritance diagram for ilErrorHandling:
+ Collaboration diagram for ilErrorHandling:

Public Member Functions

 __construct ()
 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)
 
 handlePreWhoops ($level, $message, $file, $line)
 
- Public Member Functions inherited from PEAR
 __construct ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). 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...
 
 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...
 
- Static Public Member Functions inherited from PEAR
static & 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...
 
static setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. 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

 initWhoopsHandlers ()
 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 $whoops_handlers_registered = false
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilErrorHandling::__construct ( )

Constructor public.

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

References array, and initWhoopsHandlers().

75  {
76  parent::__construct();
77 
78  // init vars
79  $this->DEBUG_ENV = true;
80  $this->FATAL = 1;
81  $this->WARNING = 2;
82  $this->MESSAGE = 3;
83 
84  $this->error_obj = false;
85 
86  $this->initWhoopsHandlers();
87 
88  // somehow we need to get rid of the whoops error handler
89  restore_error_handler();
90  set_error_handler(array($this, "handlePreWhoops"));
91  }
Create styles array
The data for the language used.
initWhoopsHandlers()
Initialize Error and Exception Handlers.
+ Here is the call graph for this function:

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

References $ilLog, and exit.

294  {
295  global $ilLog;
296 
297  switch ($errno) {
298  case E_USER_ERROR:
299  $ilLog->write('PHP errror: ' . $errstr . '. FATAL error on line ' . $errline . ' in file ' . $errfile);
300  unset($ilLog);
301  exit(1);
302 
303  case E_USER_WARNING:
304  $ilLog->write('PHP warning: [' . $errno . '] ' . $errstr . ' on line ' . $errline . ' in file ' . $errfile);
305  break;
306 
307  }
308  return true;
309  }

◆ appendMessage()

ilErrorHandling::appendMessage (   $a_message)

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

References getMessage().

277  {
278  if ($this->getMessage()) {
279  $this->message .= "<br /> ";
280  }
281  $this->message .= $a_message;
282  }
+ Here is the call graph for this function:

◆ defaultHandler()

ilErrorHandling::defaultHandler ( )
protected

Get a default error handler.

Returns
Whoops

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

References $lng, $message, ilLoggingErrorSettings\getInstance(), ilUtil\redirect(), ilUtil\sendFailure(), and ilLoggingErrorFileStorage\write().

Referenced by getHandler().

343  {
344  // php7-todo : alex, 1.3.2016: Exception -> Throwable, please check
345  return new CallbackHandler(function ($exception, Inspector $inspector, Run $run) {
346  global $lng;
347 
348  require_once("Services/Logging/classes/error/class.ilLoggingErrorSettings.php");
349  require_once("Services/Logging/classes/error/class.ilLoggingErrorFileStorage.php");
350  require_once("Services/Utilities/classes/class.ilUtil.php");
351 
352  $session_id = substr(session_id(), 0, 5);
353  $random = new \ilRandom();
354  $err_num = $random->int(1, 9999);
355  $file_name = $session_id . "_" . $err_num;
356 
358  if (!empty($logger->folder())) {
359  $lwriter = new ilLoggingErrorFileStorage($inspector, $logger->folder(), $file_name);
360  $lwriter->write();
361  }
362 
363  //Use $lng if defined or fallback to english
364  if ($lng !== null) {
365  $lng->loadLanguageModule('logging');
366  $message = sprintf($lng->txt("log_error_message"), $file_name);
367 
368  if ($logger->mail()) {
369  $message .= " " . sprintf($lng->txt("log_error_message_send_mail"), $logger->mail(), $file_name, $logger->mail());
370  }
371  } else {
372  $message = "Error " . $file_name . " occurred.";
373 
374  if ($logger->mail()) {
375  $message .= ' ' . 'Please send a mail to <a href="mailto:' . $logger->mail() . '?subject=code: ' . $file_name . '">' . $logger->mail() . '%s</a>';
376  }
377  }
378 
380  ilUtil::redirect("error.php");
381  });
382  }
Saves error informations into file.
catch(Exception $e) $message
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $lng
Definition: privfeed.php:17
Wrapper for Closures passed as handlers.
static redirect($a_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 388 of file class.ilErrorHandling.php.

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

Referenced by ilSetupErrorHandling\getHandler(), and getHandler().

389  {
390  global $ilLog;
391 
392  switch (ERROR_HANDLER) {
393  case "TESTING":
394  return new ilTestingHandler();
395  case "PLAIN_TEXT":
396  return new ilPlainTextHandler();
397  case "PRETTY_PAGE":
398  return new PrettyPageHandler();
399  default:
400  if ($ilLog) {
401  $ilLog->write("Unknown or undefined error handler '" . ERROR_HANDLER . "'. "
402  . "Falling back to PrettyPageHandler.");
403  }
404  return new PrettyPageHandler();
405  }
406  }
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 153 of file class.ilErrorHandling.php.

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

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

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

130  {
131  // TODO: * Use Whoops in production mode? This would require an appropriate
132  // error-handler.
133  // * Check for context? The current implementation e.g. would output HTML for
134  // for SOAP.
135 
136  if ($this->isDevmodeActive()) {
137  return $this->devmodeHandler();
138  }
139 
140  return $this->defaultHandler();
141  }
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 315 of file class.ilErrorHandling.php.

References ilRuntime\getInstance().

Referenced by initWhoopsHandlers().

316  {
317  return ilRuntime::getInstance();
318  }
static getInstance()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLastError()

ilErrorHandling::getLastError ( )

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

144  {
145  return $this->error_obj;
146  }

◆ getMessage()

ilErrorHandling::getMessage ( )

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

References $message.

Referenced by appendMessage().

269  {
270  return $this->message;
271  }
catch(Exception $e) $message
+ Here is the caller graph for this function:

◆ getWhoops()

ilErrorHandling::getWhoops ( )
protected

Get an instance of Whoops/Run.

Returns
Whoops

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

Referenced by initWhoopsHandlers().

325  {
326  return new Run();
327  }
+ Here is the caller graph for this function:

◆ handlePreWhoops()

ilErrorHandling::handlePreWhoops (   $level,
  $message,
  $file,
  $line 
)

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

References $file, $ilLog, $message, and isDevmodeActive().

433  {
434  global $ilLog;
435 
436  if ($level & error_reporting()) {
437 
438  // correct-with-php5-removal JL start
439  // ignore all E_STRICT that are E_NOTICE (or nothing at all) in PHP7
440  if (version_compare(PHP_VERSION, '7.0.0', '<')) {
441  if ($level == E_STRICT) {
442  if (!stristr($message, "should be compatible") &&
443  !stristr($message, "should not be called statically") &&
444  !stristr($message, "should not be abstract")) {
445  return true;
446  };
447  }
448  }
449  // correct-with-php5-removal end
450 
451  if (!$this->isDevmodeActive()) {
452  // log E_USER_NOTICE, E_STRICT, E_DEPRECATED, E_USER_DEPRECATED only
453  if ($level >= E_USER_NOTICE) {
454  if ($ilLog) {
455  $severity = Whoops\Util\Misc::TranslateErrorCode($level);
456  $ilLog->write("\n\n" . $severity . " - " . $message . "\n" . $file . " - line " . $line . "\n");
457  }
458  return true;
459  }
460  }
461 
462  // trigger whoops error handling
463  if ($this->whoops) {
464  return $this->whoops->handleError($level, $message, $file, $line);
465  }
466  }
467 
468  return false;
469  }
isDevmodeActive()
Is the DEVMODE switched on?
catch(Exception $e) $message
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:

◆ initWhoopsHandlers()

ilErrorHandling::initWhoopsHandlers ( )
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 101 of file class.ilErrorHandling.php.

References getIlRuntime(), and getWhoops().

Referenced by __construct().

102  {
103  if (self::$whoops_handlers_registered) {
104  // Only register whoops error handlers once.
105  return;
106  }
107 
108  $ilRuntime = $this->getIlRuntime();
109  $this->whoops = $this->getWhoops();
110 
111  $this->whoops->pushHandler(new ilDelegatingHandler($this));
112 
113  if ($ilRuntime->shouldLogErrors()) {
114  $this->whoops->pushHandler($this->loggingHandler());
115  }
116 
117  $this->whoops->register();
118 
119  self::$whoops_handlers_registered = true;
120  }
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 333 of file class.ilErrorHandling.php.

References defined.

Referenced by getHandler(), and handlePreWhoops().

334  {
335  return defined("DEVMODE") && (int) DEVMODE === 1;
336  }
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
+ Here is the caller graph for this function:

◆ setMessage()

ilErrorHandling::setMessage (   $a_message)

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

273  {
274  $this->message = $a_message;
275  }

Field Documentation

◆ $DEBUG_ENV

ilErrorHandling::$DEBUG_ENV

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

◆ $FATAL

ilErrorHandling::$FATAL

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

Referenced by errorHandler().

◆ $MESSAGE

ilErrorHandling::$MESSAGE

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

Referenced by errorHandler().

◆ $WARNING

ilErrorHandling::$WARNING

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

Referenced by errorHandler().

◆ $whoops_handlers_registered

ilErrorHandling::$whoops_handlers_registered = false
staticprotected

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


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