ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilErrorHandling Class Reference
+ Inheritance diagram for ilErrorHandling:
+ Collaboration diagram for ilErrorHandling:

Public Member Functions

 __construct ()
 Constructor @access 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 @access 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...
 
 addEditorSupport (PrettyPageHandler $handler)
 
 applyEditorPathTranslations (string &$file, array $pathTranslations)
 
 parseEditorPathTranslation (string $pathTranslationConfig)
 

Static Protected Attributes

static $whoops_handlers_registered = false
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilErrorHandling::__construct ( )

Constructor @access public.

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

72 {
74
75 // init vars
76 $this->DEBUG_ENV = true;
77 $this->FATAL = 1;
78 $this->WARNING = 2;
79 $this->MESSAGE = 3;
80
81 $this->error_obj = false;
82
83 $this->initWhoopsHandlers();
84
85 // somehow we need to get rid of the whoops error handler
86 restore_error_handler();
87 set_error_handler(array($this, "handlePreWhoops"));
88 }
initWhoopsHandlers()
Initialize Error and Exception Handlers.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct(), and initWhoopsHandlers().

+ 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!!!

@access public

Parameters

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

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 }
exit
Definition: login.php:29

References $ilLog, and exit.

◆ addEditorSupport()

ilErrorHandling::addEditorSupport ( PrettyPageHandler  $handler)
protected
Parameters
PrettyPageHandler$handler

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

419 {
420 $editorUrl = defined('ERROR_EDITOR_URL') ? ERROR_EDITOR_URL : '';
421 if (!is_string($editorUrl) || 0 === strlen($editorUrl)) {
422 return;
423 }
424
425 $pathTranslationConfig = defined('ERROR_EDITOR_PATH_TRANSLATIONS') ? ERROR_EDITOR_PATH_TRANSLATIONS : '';
426
427 $pathTranslations = $this->parseEditorPathTranslation($pathTranslationConfig);
428
429 $handler->setEditor(function ($file, $line) use ($editorUrl, $pathTranslations) {
430 $this->applyEditorPathTranslations($file, $pathTranslations);
431
432 return str_ireplace(
433 ['[FILE]', '[LINE]'],
434 [$file, $line],
435 $editorUrl
436 );
437 });
438 }
parseEditorPathTranslation(string $pathTranslationConfig)
applyEditorPathTranslations(string &$file, array $pathTranslations)

References applyEditorPathTranslations(), and parseEditorPathTranslation().

Referenced by devmodeHandler().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendMessage()

ilErrorHandling::appendMessage (   $a_message)

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

277 {
278 if ($this->getMessage()) {
279 $this->message .= "<br /> ";
280 }
281 $this->message .= $a_message;
282 }

References getMessage().

+ Here is the call graph for this function:

◆ applyEditorPathTranslations()

ilErrorHandling::applyEditorPathTranslations ( string &  $file,
array  $pathTranslations 
)
protected
Parameters
string$file
array$pathTranslations

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

445 {
446 foreach ($pathTranslations as $from => $to) {
447 $file = preg_replace('@' . $from . '@', $to, $file);
448 }
449 }

Referenced by addEditorSupport().

+ Here is the caller graph for this function:

◆ defaultHandler()

ilErrorHandling::defaultHandler ( )
protected

Get a default error handler.

Returns
Whoops\Handler

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

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 = 'Sorry, an error occured. A logfile has been created which can be identified via the code "' . $file_name . '"';
373
374 if ($logger->mail()) {
375 $message .= ' ' . 'Please send a mail to <a href="mailto:' . $logger->mail() . '?subject=code: ' . $file_name . '">' . $logger->mail() . '</a>';
376 }
377 }
378
380 ilUtil::redirect("error.php");
381 });
382 }
Saves error informations into file.
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$lng
$message
Definition: xapiexit.php:14

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

Referenced by getHandler().

+ 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\Handler\HandlerInterface

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

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 // fallthrough
399 default:
400 if ((!defined('ERROR_HANDLER') || ERROR_HANDLER != 'PRETTY_PAGE') && $ilLog) {
401 $ilLog->write(
402 "Unknown or undefined error handler '" . ERROR_HANDLER . "'. " .
403 "Falling back to PrettyPageHandler."
404 );
405 }
406
407 $prettyPageHandler = new PrettyPageHandler();
408
409 $this->addEditorSupport($prettyPageHandler);
410
411 return $prettyPageHandler;
412 }
413 }
addEditorSupport(PrettyPageHandler $handler)
A Whoops error handler for testing.

References $ilLog, and addEditorSupport().

Referenced by getHandler().

+ 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 @access private

Parameters
objectError

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

151 {
152 global $log;
153
154 // see bug 18499 (some calls to raiseError do not pass a code, which leads to security issues, if these calls
155 // are done due to permission checks)
156 if ($a_error_obj->getCode() == null) {
157 $a_error_obj->code = $this->WARNING;
158 }
159
160 $this->error_obj = &$a_error_obj;
161 //echo "-".$_SESSION["referer"]."-";
162 if ($_SESSION["failure"] && substr($a_error_obj->getMessage(), 0, 22) != "Cannot find this block") {
163 $m = "Fatal Error: Called raise error two times.<br>" .
164 "First error: " . $_SESSION["failure"] . '<br>' .
165 "Last Error:" . $a_error_obj->getMessage();
166 //return;
167 $log->write($m);
168 #$log->writeWarning($m);
169 #$log->logError($a_error_obj->getCode(), $m);
170 unset($_SESSION["failure"]);
171 die($m);
172 }
173
174 if (substr($a_error_obj->getMessage(), 0, 22) == "Cannot find this block") {
175 if (DEVMODE == 1) {
176 echo "<b>DEVMODE</b><br><br>";
177 echo "<b>Template Block not found.</b><br>";
178 echo "You used a template block in your code that is not available.<br>";
179 echo "Native Messge: <b>" . $a_error_obj->getMessage() . "</b><br>";
180 if (is_array($a_error_obj->backtrace)) {
181 echo "Backtrace:<br>";
182 foreach ($a_error_obj->backtrace as $b) {
183 if ($b["function"] == "setCurrentBlock" &&
184 basename($b["file"]) != "class.ilTemplate.php") {
185 echo "<b>";
186 }
187 echo "File: " . $b["file"] . ", ";
188 echo "Line: " . $b["line"] . ", ";
189 echo $b["function"] . "()<br>";
190 if ($b["function"] == "setCurrentBlock" &&
191 basename($b["file"]) != "class.ilTemplate.php") {
192 echo "</b>";
193 }
194 }
195 }
196 exit;
197 }
198 return;
199 }
200
201 if (is_object($log) and $log->enabled == true) {
202 $log->write($a_error_obj->getMessage());
203 #$log->logError($a_error_obj->getCode(),$a_error_obj->getMessage());
204 }
205
206 //echo $a_error_obj->getCode().":"; exit;
207 if ($a_error_obj->getCode() == $this->FATAL) {
208 trigger_error(stripslashes($a_error_obj->getMessage()), E_USER_ERROR);
209 exit();
210 }
211
212 if ($a_error_obj->getCode() == $this->WARNING) {
213 if ($this->DEBUG_ENV) {
214 $message = $a_error_obj->getMessage();
215 } else {
216 $message = "Under Construction";
217 }
218
219 $_SESSION["failure"] = $message;
220
221 if (!defined("ILIAS_MODULE")) {
222 ilUtil::redirect("error.php");
223 } else {
224 ilUtil::redirect("../error.php");
225 }
226 }
227
228 if ($a_error_obj->getCode() == $this->MESSAGE) {
229 $_SESSION["failure"] = $a_error_obj->getMessage();
230 // save post vars to session in case of error
231 $_SESSION["error_post_vars"] = $_POST;
232
233 if (empty($_SESSION["referer"])) {
234 $dirname = dirname($_SERVER["PHP_SELF"]);
235 $ilurl = parse_url(ILIAS_HTTP_PATH);
236
237 $subdir = '';
238 if (is_array($ilurl) && array_key_exists('path', $ilurl) && strlen($ilurl['path'])) {
239 $subdir = substr(strstr($dirname, (string) $ilurl["path"]), strlen((string) $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 }
$_POST["username"]
$_SESSION["AccountId"]
$i
Definition: metadata.php:24
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
$log
Definition: result.php:15

References $_POST, $_SERVER, $_SESSION, Vendor\Package\$b, $i, $log, $message, $WARNING, exit, ILIAS_HTTP_PATH, and ilUtil\redirect().

+ 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\Handler

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

127 {
128 // TODO: * Use Whoops in production mode? This would require an appropriate
129 // error-handler.
130 // * Check for context? The current implementation e.g. would output HTML for
131 // for SOAP.
132
133 if ($this->isDevmodeActive()) {
134 return $this->devmodeHandler();
135 }
136
137 return $this->defaultHandler();
138 }
devmodeHandler()
Get the handler to be used in DEVMODE.
isDevmodeActive()
Is the DEVMODE switched on?
defaultHandler()
Get a default error handler.

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

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

316 {
317 return ilRuntime::getInstance();
318 }
static getInstance()

References ilRuntime\getInstance().

Referenced by initWhoopsHandlers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLastError()

ilErrorHandling::getLastError ( )

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

141 {
142 return $this->error_obj;
143 }

◆ getMessage()

ilErrorHandling::getMessage ( )

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

269 {
270 return $this->message;
271 }

References $message.

Referenced by appendMessage().

+ Here is the caller graph for this function:

◆ getWhoops()

ilErrorHandling::getWhoops ( )
protected

Get an instance of Whoops/Run.

Returns
Whoops\Run

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

325 {
326 return new Run();
327 }

Referenced by initWhoopsHandlers().

+ Here is the caller graph for this function:

◆ handlePreWhoops()

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

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

495 {
496 global $ilLog;
497
498 if ($level & error_reporting()) {
499
500 // correct-with-php5-removal JL start
501 // ignore all E_STRICT that are E_NOTICE (or nothing at all) in PHP7
502 if (version_compare(PHP_VERSION, '7.0.0', '<')) {
503 if ($level == E_STRICT) {
504 if (!stristr($message, "should be compatible") &&
505 !stristr($message, "should not be called statically") &&
506 !stristr($message, "should not be abstract")) {
507 return true;
508 };
509 }
510 }
511 // correct-with-php5-removal end
512
513 if (!$this->isDevmodeActive()) {
514 // log E_USER_NOTICE, E_STRICT, E_DEPRECATED, E_USER_DEPRECATED only
515 if ($level >= E_USER_NOTICE) {
516 if ($ilLog) {
517 $severity = Whoops\Util\Misc::TranslateErrorCode($level);
518 $ilLog->write("\n\n" . $severity . " - " . $message . "\n" . $file . " - line " . $line . "\n");
519 }
520 return true;
521 }
522 }
523
524 // trigger whoops error handling
525 if ($this->whoops) {
526 return $this->whoops->handleError($level, $message, $file, $line);
527 }
528 }
529
530 return false;
531 }

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

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

99 {
100 if (self::$whoops_handlers_registered) {
101 // Only register whoops error handlers once.
102 return;
103 }
104
105 $ilRuntime = $this->getIlRuntime();
106 $this->whoops = $this->getWhoops();
107
108 $this->whoops->pushHandler(new ilDelegatingHandler($this));
109
110 if ($ilRuntime->shouldLogErrors()) {
111 $this->whoops->pushHandler($this->loggingHandler());
112 }
113
114 $this->whoops->register();
115
116 self::$whoops_handlers_registered = true;
117 }
getWhoops()
Get an instance of Whoops/Run.
getIlRuntime()
Get ilRuntime.

References getIlRuntime(), and getWhoops().

Referenced by __construct().

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

334 {
335 return defined("DEVMODE") && (int) DEVMODE === 1;
336 }

Referenced by getHandler(), and handlePreWhoops().

+ Here is the caller graph for this function:

◆ parseEditorPathTranslation()

ilErrorHandling::parseEditorPathTranslation ( string  $pathTranslationConfig)
protected
Parameters
string$pathTranslationConfig
Returns
array

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

457 {
458 $pathTranslations = [];
459
460 $mappings = explode('|', $pathTranslationConfig);
461 foreach ($mappings as $mapping) {
462 $parts = explode(',', $mapping);
463 $pathTranslations[trim($parts[0])] = trim($parts[1]);
464 }
465
466 return $pathTranslations;
467 }

Referenced by addEditorSupport().

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

◆ $FATAL

ilErrorHandling::$FATAL

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

◆ $MESSAGE

ilErrorHandling::$MESSAGE

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

◆ $WARNING

ilErrorHandling::$WARNING

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

Referenced by errorHandler().

◆ $whoops_handlers_registered

ilErrorHandling::$whoops_handlers_registered = false
staticprotected

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


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