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. More... | |
static | getLogMessage (Throwable $e) |
Get a message formatting the throwable message and its origin. More... | |
static | getLogNormalMessage (Throwable $e) |
Get a normalised message for formatting with PSR-3 log event context. More... | |
static | getPublicLogMessage (Throwable $e) |
static | getRedactedTrace (Throwable $e) |
Return a copy of a throwable's backtrace as an array. More... | |
static | getRedactedTraceAsString (Throwable $e) |
Generate a string representation of a throwable's stack trace. More... | |
static | getStructuredExceptionData (Throwable $e, $catcher=self::CAUGHT_BY_OTHER) |
Get a structured representation of a Throwable. More... | |
static | getURL () |
If the exception occurred in the course of responding to a request, returns the requested URL. More... | |
static | handleError ( $level, $message, $file=null, $line=null) |
Handler for set_error_handler() callback notifications. More... | |
static | handleException (Throwable $e, $catcher=self::CAUGHT_BY_OTHER) |
Exception handler which simulates the appropriate catch() handling: More... | |
static | handleFatalError () |
Callback used as a registered shutdown function. More... | |
static | handleUncaughtException (Throwable $e) |
Callback to use with PHP's set_exception_handler. More... | |
static | installHandler (bool $logExceptionBacktrace=true, bool $propagateErrors=true) |
Install handlers with PHP. More... | |
static | jsonSerializeException (Throwable $e, $pretty=false, $escaping=0, $catcher=self::CAUGHT_BY_OTHER) |
Serialize a Throwable object to JSON. More... | |
static | logException (Throwable $e, $catcher=self::CAUGHT_BY_OTHER, $extraData=[]) |
Log a throwable to the exception log (if enabled). More... | |
static | prettyPrintTrace (array $trace, $pad='') |
Generate a string representation of a stacktrace. More... | |
static | redactTrace (array $trace) |
Redact a stacktrace generated by Throwable::getTrace(), debug_backtrace() or similar means. More... | |
static | rollbackMasterChangesAndLog (Throwable $e, $catcher=self::CAUGHT_BY_OTHER) |
static | rollbackPrimaryChangesAndLog (Throwable $e, $catcher=self::CAUGHT_BY_OTHER) |
Roll back any open database transactions and log the stack trace of the throwable. More... | |
Static Protected Member Functions | |
static | report (Throwable $e) |
Report a throwable to the user. More... | |
Static Protected Attributes | |
static array | $fatalErrorTypes |
Error types that, if unhandled, are fatal to the request. More... | |
static string null | $reservedMemory |
Handler class for MWExceptions.
Definition at line 35 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 601 of file MWExceptionHandler.php.
References getURL().
Referenced by logException().
|
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 532 of file MWExceptionHandler.php.
References getURL().
Referenced by MediaWiki\ResourceLoader\ResourceLoader\formatExceptionNoComment(), MWException\getHTML(), MWExceptionRenderer\getHTML(), MWException\getText(), and MWExceptionRenderer\output().
|
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 560 of file MWExceptionHandler.php.
|
static |
Throwable | $e |
Definition at line 581 of file MWExceptionHandler.php.
Referenced by MediaWiki\ResourceLoader\ResourceLoader\formatExceptionNoComment(), and MWExceptionRenderer\output().
|
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 480 of file MWExceptionHandler.php.
Referenced by MediaWiki\Logger\LegacyLogger\format(), and getStructuredExceptionData().
|
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 422 of file MWExceptionHandler.php.
References prettyPrintTrace().
Referenced by MediaWiki\ResourceLoader\ResourceLoader\formatExceptionNoComment(), MWException\getHTML(), MWExceptionRenderer\getHTML(), MWException\getText(), MediaWiki\Logger\Monolog\LogstashFormatter\normalizeException(), MWExceptionRenderer\output(), and ApiMain\substituteResultWithError().
|
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 632 of file MWExceptionHandler.php.
References getRedactedTrace(), and getURL().
Referenced by MediaWiki\Rest\ResponseFactory\createFromException().
|
static |
If the exception occurred in the course of responding to a request, returns the requested URL.
Otherwise, returns false.
Definition at line 512 of file MWExceptionHandler.php.
References $wgRequest.
Referenced by MWException\getHTML(), MWExceptionRenderer\getHTML(), getLogContext(), getLogMessage(), and getStructuredExceptionData().
|
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 268 of file MWExceptionHandler.php.
References $file, and MWDebug\parseCallerDescription().
|
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 249 of file MWExceptionHandler.php.
References report(), and rollbackPrimaryChangesAndLog().
Referenced by handleUncaughtException(), and MediaWiki\run().
|
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 361 of file MWExceptionHandler.php.
References $file.
|
static |
Callback to use with PHP's set_exception_handler.
Throwable | $e |
Definition at line 218 of file MWExceptionHandler.php.
References 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 88 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 720 of file MWExceptionHandler.php.
References FormatJson\encode().
Referenced by logException().
|
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 744 of file MWExceptionHandler.php.
References FormatJson\ALL_OK, getLogContext(), and jsonSerializeException().
Referenced by JobQueueEnqueueUpdate\doUpdate(), MediaWiki\emitBufferedStatsdData(), MediaWiki\SpecialPage\ChangesListSpecialPage\execute(), MediaWiki\ResourceLoader\ResourceLoader\outputErrorAndLog(), MediaWiki\preOutputCommit(), rollbackPrimaryChangesAndLog(), and MediaWiki\User\User\saveSettings().
|
static |
Generate a string representation of a stacktrace.
array | $trace | |
string | $pad | Constant padding to add to each line of trace |
Definition at line 435 of file MWExceptionHandler.php.
Referenced by MediaWiki\Logger\LegacyLogger\format(), getRedactedTraceAsString(), and MediaWiki\Logger\Monolog\LineFormatter\normalizeExceptionArray().
|
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 494 of file MWExceptionHandler.php.
Referenced by MediaWiki\Logger\Monolog\LineFormatter\exceptionAsArray().
|
staticprotected |
Report a throwable to the user.
Throwable | $e |
Definition at line 125 of file MWExceptionHandler.php.
References MWExceptionRenderer\AS_PRETTY, MWExceptionRenderer\AS_RAW, and MWExceptionRenderer\output().
Referenced by handleException().
|
static |
Throwable | $e | |
string | $catcher | CAUGHT_BY_* class constant indicating what caught the error |
Definition at line 204 of file MWExceptionHandler.php.
References rollbackPrimaryChangesAndLog(), and wfDeprecated().
|
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 190 of file MWExceptionHandler.php.
References logException().
Referenced by MediaWiki\doPostOutputShutdown(), RefreshSecondaryDataUpdate\doUpdate(), ApiMain\handleException(), handleException(), MediaWiki\Rest\Reporter\MWErrorReporter\reportError(), rollbackMasterChangesAndLog(), AssembleUploadChunksJob\run(), and PublishStashedFileJob\run().
|
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 56 of file MWExceptionHandler.php.
|
staticprotected |
Definition at line 44 of file MWExceptionHandler.php.