ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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...
 

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 @access public.

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

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 }
initWhoopsHandlers()
Initialize Error and Exception Handlers.

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

314 {
315 global $ilLog;
316
317 switch($errno)
318 {
319 case E_USER_ERROR:
320 $ilLog->write('PHP errror: '.$errstr.'. FATAL error on line '.$errline.' in file '.$errfile);
321 unset($ilLog);
322 exit(1);
323
324 case E_USER_WARNING:
325 $ilLog->write('PHP warning: ['.$errno.'] '.$errstr.' on line '.$errline.' in file '.$errfile);
326 break;
327
328 }
329 return true;
330 }

References $ilLog, and exit.

◆ appendMessage()

ilErrorHandling::appendMessage (   $a_message)

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

296 {
297 if($this->getMessage())
298 {
299 $this->message .= "<br /> ";
300 }
301 $this->message .= $a_message;
302 }

References getMessage().

+ Here is the call graph for this function:

◆ defaultHandler()

ilErrorHandling::defaultHandler ( )
protected

Get a default error handler.

Returns
Whoops\Handler

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

360 {
361 // php7-todo : alex, 1.3.2016: Exception -> Throwable, please check
362 return new CallbackHandler(function($exception, Inspector $inspector, Run $run) {
363 global $lng;
364
365 require_once("Services/Logging/classes/error/class.ilLoggingErrorSettings.php");
366 require_once("Services/Logging/classes/error/class.ilLoggingErrorFileStorage.php");
367 require_once("Services/Utilities/classes/class.ilUtil.php");
368
369 $session_id = substr(session_id(),0,5);
370 $err_num = rand(1, 9999);
371 $file_name = $session_id."_".$err_num;
372
374 if(!empty($logger->folder())) {
375 $lwriter = new ilLoggingErrorFileStorage($inspector, $logger->folder(), $file_name);
376 $lwriter->write();
377 }
378
379 //Use $lng if defined or fallback to english
380 if($lng !== null) {
381 $lng->loadLanguageModule('logging');
382 $message = sprintf($lng->txt("log_error_message"), $file_name);
383
384 if($logger->mail()) {
385 $message .= " ".sprintf($lng->txt("log_error_message_send_mail"), $logger->mail(), $file_name, $logger->mail());
386 }
387 } else {
388 $message = "Error ".$file_name." occurred.";
389
390 if($logger->mail()) {
391 $message .= ' '.'Please send a mail to <a href="mailto:'.$logger->mail().'?subject=code: '.$file_name.'">'.$logger->mail().'%s</a>';
392 }
393 }
394
395 ilUtil::sendFailure($message, true);
396 ilUtil::redirect("error.php");
397 });
398 }
sprintf('%.4f', $callTime)
Wrapper for Closures passed as handlers.
Saves error informations into file.
static redirect($a_script)
http redirect to other script
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $lng
Definition: privfeed.php:17

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

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

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

404 {
405 global $ilLog;
406
407 switch (ERROR_HANDLER) {
408 case "TESTING":
409 return new ilTestingHandler();
410 case "PLAIN_TEXT":
411 return new ilPlainTextHandler();
412 case "PRETTY_PAGE":
413 return new PrettyPageHandler();
414 default:
415 if ($ilLog) {
416 $ilLog->write("Unknown or undefined error handler '".ERROR_HANDLER."'. "
417 ."Falling back to PrettyPageHandler.");
418 }
419 return new PrettyPageHandler();
420 }
421 }
A Whoops error handler for testing.

References $ilLog.

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

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

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

References $_POST, $_SERVER, $_SESSION, $log, $WARNING, defined, exit, 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

Reimplemented in ilSetupErrorHandling.

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

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

336 {
337 return ilRuntime::getInstance();
338 }
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 141 of file class.ilErrorHandling.php.

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

◆ getMessage()

ilErrorHandling::getMessage ( )

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

288 {
289 return $this->message;
290 }

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

344 {
345 return new Run();
346 }

Referenced by initWhoopsHandlers().

+ Here is the caller graph for this function:

◆ handlePreWhoops()

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

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

447 {
448 global $ilLog;
449
450 if ($level & error_reporting()) {
451
452 // correct-with-php5-removal JL start
453 // ignore all E_STRICT that are E_NOTICE (or nothing at all) in PHP7
454 if (version_compare(PHP_VERSION, '7.0.0', '<')) {
455 if ($level == E_STRICT) {
456 if (!stristr($message, "should be compatible") &&
457 !stristr($message, "should not be called statically") &&
458 !stristr($message, "should not be abstract")) {
459 return true;
460 };
461 }
462 }
463 // correct-with-php5-removal end
464
465 if (!$this->isDevmodeActive()) {
466 // log E_USER_NOTICE, E_STRICT, E_DEPRECATED, E_USER_DEPRECATED only
467 if ($level >= E_USER_NOTICE) {
468
469 if ($ilLog) {
470 $severity = Whoops\Util\Misc::TranslateErrorCode($level);
471 $ilLog->write("\n\n".$severity." - ".$message."\n".$file." - line ".$line."\n");
472 }
473 return true;
474 }
475 }
476
477 // trigger whoops error handling
478 if($this->whoops)
479 {
480 return $this->whoops->handleError($level, $message, $file, $line);
481 }
482 }
483
484 return false;
485 }
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file

References $file, $ilLog, 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 101 of file class.ilErrorHandling.php.

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

352 {
353 return DEVMODE == 1;
354 }

Referenced by getHandler(), and handlePreWhoops().

+ Here is the caller graph for this function:

◆ setMessage()

ilErrorHandling::setMessage (   $a_message)

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

292 {
293 $this->message = $a_message;
294 }

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.

◆ $MESSAGE

ilErrorHandling::$MESSAGE

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

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