MediaWiki
1.34.0
|
Handler class for MWExceptions. More...
Static Public Member Functions | |
static | getLogContext ( $e, $catcher=self::CAUGHT_BY_OTHER) |
Get a PSR-3 log event context from an Exception. More... | |
static | getLogMessage ( $e) |
Get a message formatting the exception message and its origin. More... | |
static | getLogNormalMessage ( $e) |
Get a normalised message for formatting with PSR-3 log event context. More... | |
static | getPublicLogMessage ( $e) |
static | getRedactedTrace ( $e) |
Return a copy of an exception's backtrace as an array. More... | |
static | getRedactedTraceAsString ( $e) |
Generate a string representation of an exception's stack trace. More... | |
static | getStructuredExceptionData ( $e, $catcher=self::CAUGHT_BY_OTHER) |
Get a structured representation of an Exception. 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 ( $e) |
Exception handler which simulates the appropriate catch() handling: More... | |
static | handleFatalError ( $level=null, $message=null, $file=null, $line=null, $context=null, $trace=null) |
Dual purpose callback used as both a set_error_handler() callback and a registered shutdown function. More... | |
static | handleUncaughtException ( $e) |
Callback to use with PHP's set_exception_handler. More... | |
static | installHandler () |
Install handlers with PHP. More... | |
static | jsonSerializeException ( $e, $pretty=false, $escaping=0, $catcher=self::CAUGHT_BY_OTHER) |
Serialize an Exception object to JSON. More... | |
static | logException ( $e, $catcher=self::CAUGHT_BY_OTHER, $extraData=[]) |
Log an exception 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 Exception::getTrace(), debug_backtrace() or similar means. More... | |
static | rollbackMasterChangesAndLog ( $e) |
Roll back any open database transactions and log the stack trace of the exception. More... | |
Public Attributes | |
const | CAUGHT_BY_HANDLER = 'mwe_handler' |
const | CAUGHT_BY_OTHER = 'other' |
Static Protected Member Functions | |
static | logError (ErrorException $e, $channel, $level=LogLevel::ERROR) |
Log an exception that wasn't thrown but made to wrap an error. More... | |
static | report ( $e) |
Report an exception to the user. More... | |
Static Protected Attributes | |
static | $fatalErrorTypes |
Error types that, if unhandled, are fatal to the request. More... | |
static | $handledFatalCallback = false |
static | $reservedMemory |
Handler class for MWExceptions.
Definition at line 30 of file MWExceptionHandler.php.
|
static |
Get a PSR-3 log event context from an Exception.
Creates a structured array containing information about the provided exception that can be used to augment a log message sent to a PSR-3 logger.
Exception | Throwable | $e | |
string | $catcher | CAUGHT_BY_* class constant indicating what caught the error |
Definition at line 562 of file MWExceptionHandler.php.
References WebRequest\getRequestId(), and getURL().
Referenced by logException().
|
static |
Get a message formatting the exception message and its origin.
Exception | Throwable | $e |
Definition at line 510 of file MWExceptionHandler.php.
References $file, $line, $type, WebRequest\getRequestId(), and getURL().
Referenced by MWException\getHTML(), MWExceptionRenderer\getHTML(), MWException\getText(), MWExceptionRenderer\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.
Exception | Throwable | $e |
Definition at line 530 of file MWExceptionHandler.php.
|
static |
Exception | Throwable | $e |
Definition at line 543 of file MWExceptionHandler.php.
References $type, and WebRequest\getRequestId().
Referenced by MWExceptionRenderer\output().
|
static |
Return a copy of an exception's backtrace as an array.
Like Exception::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).
Exception | Throwable | $e |
Definition at line 463 of file MWExceptionHandler.php.
Referenced by MediaWiki\Logger\LegacyLogger\format(), and getStructuredExceptionData().
|
static |
Generate a string representation of an exception's stack trace.
Like Exception::getTraceAsString, but replaces argument values with argument type or class name.
Exception | Throwable | $e |
Definition at line 404 of file MWExceptionHandler.php.
References prettyPrintTrace().
Referenced by MWException\getHTML(), MWExceptionRenderer\getHTML(), MWException\getText(), MWExceptionRenderer\getText(), MediaWiki\Logger\Monolog\LogstashFormatter\normalizeException(), MWExceptionRenderer\output(), and ApiMain\substituteResultWithError().
|
static |
Get a structured representation of an Exception.
Returns an array of structured data (class, message, code, file, backtrace) derived from the given exception. The backtrace information will be redacted as per getRedactedTraceAsArray().
Exception | Throwable | $e | |
string | $catcher | CAUGHT_BY_* class constant indicating what caught the error |
Definition at line 583 of file MWExceptionHandler.php.
References $wgLogExceptionBacktrace, getRedactedTrace(), WebRequest\getRequestId(), 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 495 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). If the raised error is a fatal error type (only under HHVM) delegate to handleFatalError() instead.
int | $level | Error level raised |
string | $message | |
string | null | $file | |
int | null | $line |
Definition at line 216 of file MWExceptionHandler.php.
References $file, $line, $wgPropagateErrors, handleFatalError(), and logError().
|
static |
Exception handler which simulates the appropriate catch() handling:
try { ... } catch ( Exception $e ) { $e->report(); } catch ( Exception $e ) { echo $e->__toString(); }
Exception | Throwable | $e |
Definition at line 193 of file MWExceptionHandler.php.
References report(), and rollbackMasterChangesAndLog().
Referenced by handleUncaughtException(), and MediaWiki\run().
|
static |
Dual purpose callback used as both a set_error_handler() callback and a registered shutdown function.
Receive a callback from the interpreter for a raised error or system shutdown, check for a fatal error, and log to the 'fatal' logging channel.
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.
int | null | $level | Error level raised |
string | null | $message | Error message |
string | null | $file | File that error was raised in |
int | null | $line | Line number error was raised at |
array | null | $context | Active symbol table point of error |
array | null | $trace | Backtrace at point of error (undocumented HHVM feature) |
Definition at line 306 of file MWExceptionHandler.php.
References $file, $line, WebRequest\getGlobalRequestURL(), and WebRequest\getRequestId().
Referenced by handleError().
|
static |
Callback to use with PHP's set_exception_handler.
Exception | Throwable | $e |
Definition at line 166 of file MWExceptionHandler.php.
References handleException(), and wfIsCLI().
|
static |
Install handlers with PHP.
Definition at line 76 of file MWExceptionHandler.php.
|
static |
Serialize an Exception 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 exception 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 Exception::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).
Exception | 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 670 of file MWExceptionHandler.php.
References FormatJson\encode().
Referenced by logError(), and logException().
|
staticprotected |
Log an exception that wasn't thrown but made to wrap an error.
ErrorException | $e | |
string | $channel | |
string | $level |
Definition at line 721 of file MWExceptionHandler.php.
References FormatJson\ALL_OK, CAUGHT_BY_HANDLER, jsonSerializeException(), and Hooks\run().
Referenced by handleError().
|
static |
Log an exception to the exception log (if enabled).
This method must not assume the exception is an MWException, it is also used to handle PHP exceptions or exceptions from other libraries.
Exception | 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 691 of file MWExceptionHandler.php.
References $context, FormatJson\ALL_OK, getLogContext(), jsonSerializeException(), and Hooks\run().
Referenced by MediaWiki\doPostOutputShutdown(), JobQueueEnqueueUpdate\doUpdate(), MediaWiki\emitBufferedStatsdData(), ChangesListSpecialPage\execute(), JobRunner\executeJob(), MediaWiki\preOutputCommit(), JobQueueGroup\push(), rollbackMasterChangesAndLog(), PageImages\Job\InitImageDataJob\run(), User\saveSettings(), and MediaWiki\triggerJobs().
|
static |
Generate a string representation of a stacktrace.
array | $trace | |
string | $pad | Constant padding to add to each line of trace |
Definition at line 416 of file MWExceptionHandler.php.
Referenced by MediaWiki\Logger\LegacyLogger\format(), getRedactedTraceAsString(), and MediaWiki\Logger\Monolog\LineFormatter\normalizeExceptionArray().
|
static |
Redact a stacktrace generated by Exception::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 477 of file MWExceptionHandler.php.
Referenced by MediaWiki\Logger\Monolog\LineFormatter\exceptionAsArray().
|
staticprotected |
Report an exception to the user.
Exception | Throwable | $e |
Definition at line 112 of file MWExceptionHandler.php.
References MWExceptionRenderer\AS_PRETTY, MWExceptionRenderer\AS_RAW, and MWExceptionRenderer\output().
Referenced by handleException().
|
static |
Roll back any open database transactions and log the stack trace of the exception.
This method is used to attempt to recover from exceptions
Exception | Throwable | $e |
Definition at line 139 of file MWExceptionHandler.php.
References logException().
Referenced by MediaWiki\doPostOutputShutdown(), JobRunner\executeJob(), handleException(), ApiMain\handleException(), AssembleUploadChunksJob\run(), and PublishStashedFileJob\run().
|
staticprotected |
Error types that, if unhandled, are fatal to the request.
On PHP 7, these error types may be thrown as Error objects, which implement Throwable (but not Exception).
On HHVM, these invoke the set_error_handler callback, similar to how (non-fatal) warnings and notices are reported, except that after this handler runs for fatal error tpyes, script execution stops!
The user will be shown an HTTP 500 Internal Server Error. As such, these should be sent to MediaWiki's "fatal" or "exception" channel. Normally, the error handler logs them to the "error" channel.
Definition at line 55 of file MWExceptionHandler.php.
|
staticprotected |
Definition at line 71 of file MWExceptionHandler.php.
|
staticprotected |
Definition at line 37 of file MWExceptionHandler.php.
const MWExceptionHandler::CAUGHT_BY_HANDLER = 'mwe_handler' |
Definition at line 31 of file MWExceptionHandler.php.
Referenced by logError().
const MWExceptionHandler::CAUGHT_BY_OTHER = 'other' |
Definition at line 32 of file MWExceptionHandler.php.