MediaWiki 1.42.0
|
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 | 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 | rollbackPrimaryChangesAndLog (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 array | $fatalErrorTypes |
Error types that, if unhandled, are fatal to the request. | |
static string null | $reservedMemory |
Handler class for MWExceptions.
Definition at line 34 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 585 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 516 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 544 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 466 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 their type or class name, and prepends the start line of the throwable.
Throwable | $e |
Definition at line 408 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 616 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 498 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 254 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 235 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 347 of file MWExceptionHandler.php.
|
static |
Callback to use with PHP's set_exception_handler.
Throwable | $e |
Definition at line 204 of file MWExceptionHandler.php.
References 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 87 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 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 704 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 728 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 421 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 480 of file MWExceptionHandler.php.
|
staticprotected |
Report a throwable to the user.
Throwable | $e |
Definition at line 124 of file MWExceptionHandler.php.
|
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 189 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 55 of file MWExceptionHandler.php.
|
staticprotected |
Definition at line 43 of file MWExceptionHandler.php.