|
MediaWiki master
|
Handler class for MWExceptions. More...
Static Public Member Functions | |
| static | getLogContext (Throwable $e, $catcher=self::CAUGHT_BY_OTHER) |
| Get a PSR-3 log event context from a Throwable. | |
| static | getLogMessage (Throwable $e) |
| Get a message formatting the throwable message and its origin. | |
| static | getLogNormalMessage (Throwable $e) |
| Get a normalised message for formatting with PSR-3 log event context. | |
| static | getPublicLogMessage (Throwable $e) |
| static | getRedactedTrace (Throwable $e) |
| Return a copy of a throwable's backtrace as an array. | |
| static | getRedactedTraceAsString (Throwable $e) |
| Generate a string representation of a throwable's stack trace. | |
| static | getStructuredExceptionData (Throwable $e, $catcher=self::CAUGHT_BY_OTHER) |
| Get a structured representation of a Throwable. | |
| static | getURL () |
| If the exception occurred in the course of responding to a request, returns the requested URL. | |
| static | handleError ( $level, $message, $file=null, $line=null) |
| Handler for set_error_handler() callback notifications. | |
| static | handleException (Throwable $e, $catcher=self::CAUGHT_BY_OTHER) |
| Exception handler which simulates the appropriate catch() handling: | |
| static | handleFatalError () |
| Callback used as a registered shutdown function. | |
| static | handleUncaughtException (Throwable $e) |
| Callback to use with PHP's set_exception_handler. | |
| static | installHandler (bool $logExceptionBacktrace=true, bool $propagateErrors=true) |
| Install handlers with PHP. | |
| static | logException (Throwable $e, $catcher=self::CAUGHT_BY_OTHER, $extraData=[]) |
| Log a throwable to the exception log (if enabled). | |
| static | prettyPrintTrace (array $trace, $pad='') |
| Generate a string representation of a stacktrace. | |
| static | redactTrace (array $trace) |
| Redact a stacktrace generated by Throwable::getTrace(), debug_backtrace() or similar means. | |
| static | rollbackPrimaryChangesAndLog (Throwable $e, $catcher=self::CAUGHT_BY_OTHER) |
| Roll back any open database transactions and log the stack trace of the throwable. | |
Public Attributes | |
| const | CAUGHT_BY_ENTRYPOINT = 'entrypoint' |
| Error caught and reported by a script entry point. | |
| const | CAUGHT_BY_HANDLER = 'mwe_handler' |
| Error caught and reported by this exception handler. | |
| const | CAUGHT_BY_OTHER = 'other' |
| Error reported by direct logException() call. | |
Static Protected Member Functions | |
| static | report (Throwable $e) |
| Report a throwable to the user. | |
Static Protected Attributes | |
| static string null | $reservedMemory |
Handler class for MWExceptions.
Definition at line 27 of file MWExceptionHandler.php.
|
static |
Get a PSR-3 log event context from a Throwable.
Creates a structured array containing information about the provided throwable that can be used to augment a log message sent to a PSR-3 logger.
| Throwable | $e | |
| string | $catcher | CAUGHT_BY_* class constant indicating what caught the error |
Definition at line 566 of file MWExceptionHandler.php.
|
static |
Get a message formatting the throwable message and its origin.
Despite the method name, this is not used for logging. It is only used for HTML or CLI output by MWExceptionRenderer.
| Throwable | $e |
Definition at line 497 of file MWExceptionHandler.php.
References $url.
|
static |
Get a normalised message for formatting with PSR-3 log event context.
Must be used together with getLogContext() to be useful.
| Throwable | $e |
Definition at line 525 of file MWExceptionHandler.php.
|
static |
|
static |
Return a copy of a throwable's backtrace as an array.
Like Throwable::getTrace, but replaces each element in each frame's argument array with the name of its class (if the element is an object) or its type (if the element is a PHP primitive).
| Throwable | $e |
Definition at line 450 of file MWExceptionHandler.php.
|
static |
Generate a string representation of a throwable's stack trace.
Like Throwable::getTraceAsString, but replaces argument values with their type or class name, and prepends the start line of the throwable.
| Throwable | $e |
Definition at line 392 of file MWExceptionHandler.php.
|
static |
Get a structured representation of a Throwable.
Returns an array of structured data (class, message, code, file, backtrace) derived from the given throwable. The backtrace information will be redacted as per getRedactedTraceAsArray().
| Throwable | $e | |
| string | $catcher | CAUGHT_BY_* class constant indicating what caught the error |
Definition at line 597 of file MWExceptionHandler.php.
|
static |
If the exception occurred in the course of responding to a request, returns the requested URL.
Otherwise, returns false.
Definition at line 480 of file MWExceptionHandler.php.
References MW_ENTRY_POINT.
|
static |
Handler for set_error_handler() callback notifications.
Receive a callback from the interpreter for a raised error, create an ErrorException, and log the exception to the 'error' logging channel(s).
| int | $level | Error level raised |
| string | $message | |
| string | null | $file | |
| int | null | $line |
Definition at line 241 of file MWExceptionHandler.php.
|
static |
Exception handler which simulates the appropriate catch() handling:
try { ... } catch ( Exception $e ) { $e->report(); } catch ( Exception $e ) { echo $e->__toString(); }
| Throwable | $e | |
| string | $catcher | CAUGHT_BY_* class constant indicating what caught the error |
Definition at line 222 of file MWExceptionHandler.php.
References MediaWiki\Exception\MWExceptionHandler\report(), and MediaWiki\Exception\MWExceptionHandler\rollbackPrimaryChangesAndLog().
Referenced by MediaWiki\Exception\MWExceptionHandler\handleUncaughtException().
|
static |
Callback used as a registered shutdown function.
This is used as callback from the interpreter at system shutdown. If the last error was not a recoverable error that we already reported, and log as fatal exception.
Special handling is included for missing class errors as they may indicate that the user needs to install 3rd-party libraries via Composer or other means.
Definition at line 333 of file MWExceptionHandler.php.
|
static |
Callback to use with PHP's set_exception_handler.
| Throwable | $e |
Definition at line 194 of file MWExceptionHandler.php.
References MediaWiki\Exception\MWExceptionHandler\handleException(), and wfIsCLI().
|
static |
Install handlers with PHP.
| bool | $logExceptionBacktrace | Whether error handlers should include a backtrace in the log. |
| bool | $propagateErrors | Whether errors should be propagated to PHP's built-in handler. |
Definition at line 78 of file MWExceptionHandler.php.
|
static |
Log a throwable to the exception log (if enabled).
This method must not assume the throwable is an MWException, it is also used to handle PHP exceptions or exceptions from other libraries.
| Throwable | $e | |
| string | $catcher | CAUGHT_BY_* class constant indicating what caught the error |
| array | $extraData | (since 1.34) Additional data to log |
Definition at line 642 of file MWExceptionHandler.php.
Referenced by MediaWiki\Exception\MWExceptionHandler\rollbackPrimaryChangesAndLog().
|
static |
Generate a string representation of a stacktrace.
| array | $trace | |
| string | $pad | Constant padding to add to each line of trace |
Definition at line 405 of file MWExceptionHandler.php.
|
static |
Redact a stacktrace generated by Throwable::getTrace(), debug_backtrace() or similar means.
Replaces each element in each frame's argument array with the name of its class (if the element is an object) or its type (if the element is a PHP primitive).
| array | $trace | Stacktrace |
Definition at line 464 of file MWExceptionHandler.php.
|
staticprotected |
Report a throwable to the user.
Definition at line 114 of file MWExceptionHandler.php.
References MediaWiki\Exception\MWExceptionRenderer\AS_PRETTY, MediaWiki\Exception\MWExceptionRenderer\AS_RAW, and MediaWiki\Exception\MWExceptionRenderer\output().
Referenced by MediaWiki\Exception\MWExceptionHandler\handleException().
|
static |
Roll back any open database transactions and log the stack trace of the throwable.
This method is used to attempt to recover from exceptions
| Throwable | $e | |
| string | $catcher | CAUGHT_BY_* class constant indicating what caught the error |
Definition at line 179 of file MWExceptionHandler.php.
References MediaWiki\Exception\MWExceptionHandler\logException().
Referenced by MediaWiki\Exception\MWExceptionHandler\handleException().
|
staticprotected |
Definition at line 36 of file MWExceptionHandler.php.
| const MediaWiki\Exception\MWExceptionHandler::CAUGHT_BY_ENTRYPOINT = 'entrypoint' |
Error caught and reported by a script entry point.
Definition at line 31 of file MWExceptionHandler.php.
| const MediaWiki\Exception\MWExceptionHandler::CAUGHT_BY_HANDLER = 'mwe_handler' |
Error caught and reported by this exception handler.
Definition at line 29 of file MWExceptionHandler.php.
| const MediaWiki\Exception\MWExceptionHandler::CAUGHT_BY_OTHER = 'other' |
Error reported by direct logException() call.
Definition at line 33 of file MWExceptionHandler.php.