MediaWiki REL1_35
|
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 () |
Install handlers with PHP. | |
static | jsonSerializeException (Throwable $e, $pretty=false, $escaping=0, $catcher=self::CAUGHT_BY_OTHER) |
Serialize a Throwable object to JSON. | |
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 | rollbackMasterChangesAndLog (Throwable $e, $catcher=self::CAUGHT_BY_OTHER) |
Roll back any open database transactions and log the stack trace of the throwable. | |
Static Protected Member Functions | |
static | report (Throwable $e) |
Report a throwable to the user. | |
Static Protected Attributes | |
static | $fatalErrorTypes |
Error types that, if unhandled, are fatal to the request. | |
static | $reservedMemory |
Static Private Member Functions | |
static | logError (ErrorException $e, $channel, $level, $catcher) |
Log an exception that wasn't thrown but made to wrap an error. | |
Handler class for MWExceptions.
Definition at line 31 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 521 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 and MWException::getText, respectively.
Throwable | $e |
Definition at line 462 of file MWExceptionHandler.php.
|
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 488 of file MWExceptionHandler.php.
|
static |
Throwable | $e |
Definition at line 501 of file MWExceptionHandler.php.
References $type.
|
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 411 of file MWExceptionHandler.php.
Referenced by MediaWiki\Logger\LegacyLogger\format().
|
static |
Generate a string representation of a throwable's stack trace.
Like Throwable::getTraceAsString, but replaces argument values with argument type or class name.
Throwable | $e |
Definition at line 352 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 542 of file MWExceptionHandler.php.
References $wgLogExceptionBacktrace.
|
static |
If the exception occurred in the course of responding to a request, returns the requested URL.
Otherwise, returns false.
Definition at line 443 of file MWExceptionHandler.php.
References $wgRequest.
|
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 202 of file MWExceptionHandler.php.
References $file, $line, and $wgPropagateErrors.
|
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 183 of file MWExceptionHandler.php.
|
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 284 of file MWExceptionHandler.php.
|
static |
Callback to use with PHP's set_exception_handler.
Throwable | $e |
Definition at line 155 of file MWExceptionHandler.php.
References wfIsCLI().
|
static |
Install handlers with PHP.
Definition at line 66 of file MWExceptionHandler.php.
|
static |
Serialize a Throwable object to JSON.
The JSON object will have keys 'id', 'file', 'line', 'message', and 'url'. These keys map to string values, with the exception of 'line', which is a number, and 'url', which may be either a string URL or or null if the throwable did not occur in the context of serving a web request.
If $wgLogExceptionBacktrace is true, it will also have a 'backtrace' key, mapped to the array return value of Throwable::getTrace, but with each element in each frame's "args" array (if set) replaced with the argument's class name (if the argument is an object) or type name (if the argument is a PHP primitive).
Throwable | $e | |
bool | $pretty | Add non-significant whitespace to improve readability (default: false). |
int | $escaping | Bitfield consisting of FormatJson::.*_OK class constants. |
string | $catcher | CAUGHT_BY_* class constant indicating what caught the error |
Definition at line 632 of file MWExceptionHandler.php.
|
staticprivate |
Log an exception that wasn't thrown but made to wrap an error.
ErrorException | $e | |
string | $channel | |
string | $level | |
string | $catcher | CAUGHT_BY_* class constant indicating what caught the error |
Definition at line 690 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 656 of file MWExceptionHandler.php.
|
static |
Generate a string representation of a stacktrace.
array | $trace | |
string | $pad | Constant padding to add to each line of trace |
Definition at line 364 of file MWExceptionHandler.php.
Referenced by MediaWiki\Logger\LegacyLogger\format().
|
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 425 of file MWExceptionHandler.php.
|
staticprotected |
Report a throwable to the user.
Throwable | $e |
Definition at line 97 of file MWExceptionHandler.php.
References MWExceptionRenderer\AS_PRETTY, MWExceptionRenderer\AS_RAW, and MWExceptionRenderer\output().
|
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 125 of file MWExceptionHandler.php.
|
staticprotected |
Error types that, if unhandled, are fatal to the request.
These error types may be thrown as Error objects, which implement Throwable (but not Exception).
The user will be shown an HTTP 500 Internal Server Error. As such, these should be sent to MediaWiki's "exception" channel. Normally, the error handler logs them to the "error" channel.
Definition at line 52 of file MWExceptionHandler.php.
|
staticprotected |
Definition at line 40 of file MWExceptionHandler.php.