MediaWiki
REL1_24
|
Handler class for MWExceptions. More...
Static Public Member Functions | |
static | getLogId (Exception $e) |
Get the ID for this error. | |
static | getLogMessage (Exception $e) |
Return the requested URL and point to file and line number from which the exception occurred. | |
static | getRedactedTrace (Exception $e) |
Return a copy of an exception's backtrace as an array. | |
static | getRedactedTraceAsString (Exception $e) |
Generate a string representation of an exception's stack trace. | |
static | getURL () |
If the exception occurred in the course of responding to a request, returns the requested URL. | |
static | handle ($e) |
Exception handler which simulates the appropriate catch() handling: | |
static | installHandler () |
Install an exception handler for MediaWiki exception types. | |
static | jsonSerializeException (Exception $e, $pretty=false, $escaping=0) |
Serialize an Exception object to JSON. | |
static | logException (Exception $e) |
Log an exception to the exception log (if enabled). | |
static | printError ($message) |
Print a message, if possible to STDERR. | |
static | rollbackMasterChangesAndLog (Exception $e) |
If there are any open database transactions, roll them back and log the stack trace of the exception that should have been caught so the transaction could be aborted properly. | |
Static Protected Member Functions | |
static | report (Exception $e) |
Report an exception to the user. |
Handler class for MWExceptions.
Definition at line 25 of file MWExceptionHandler.php.
static MWExceptionHandler::getLogId | ( | Exception $ | e | ) | [static] |
Get the ID for this error.
The ID is saved so that one can match the one output to the user (when $wgShowExceptionDetails is set to false), to the entry in the debug log.
Exception | $e |
Definition at line 229 of file MWExceptionHandler.php.
References wfRandomString().
Referenced by MWException\getHTML(), and getLogMessage().
static MWExceptionHandler::getLogMessage | ( | Exception $ | e | ) | [static] |
Return the requested URL and point to file and line number from which the exception occurred.
Exception | $e |
Definition at line 259 of file MWExceptionHandler.php.
References $file, getLogId(), and getURL().
Referenced by MWException\getHTML(), MWException\getText(), logException(), report(), and rollbackMasterChangesAndLog().
static MWExceptionHandler::getRedactedTrace | ( | Exception $ | e | ) | [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 | $e |
Definition at line 208 of file MWExceptionHandler.php.
Referenced by jsonSerializeException(), and MWExceptionHandlerTest\testGetRedactedTrace().
static MWExceptionHandler::getRedactedTraceAsString | ( | Exception $ | e | ) | [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 | $e |
Definition at line 165 of file MWExceptionHandler.php.
References as.
Referenced by MWException\getHTML(), MWException\getText(), and report().
static MWExceptionHandler::getURL | ( | ) | [static] |
If the exception occurred in the course of responding to a request, returns the requested URL.
Otherwise, returns false.
Definition at line 243 of file MWExceptionHandler.php.
References global.
Referenced by getLogMessage(), and jsonSerializeException().
static MWExceptionHandler::handle | ( | $ | e | ) | [static] |
Exception handler which simulates the appropriate catch() handling:
try { ... } catch ( MWException $e ) { $e->report(); } catch ( Exception $e ) { echo $e->__toString(); }
Exception | $e |
Definition at line 136 of file MWExceptionHandler.php.
References $e, $wgFullyInitialised, global, report(), rollbackMasterChangesAndLog(), and wfLogProfilingData().
static MWExceptionHandler::installHandler | ( | ) | [static] |
Install an exception handler for MediaWiki exception types.
Definition at line 29 of file MWExceptionHandler.php.
References array().
static MWExceptionHandler::jsonSerializeException | ( | Exception $ | e, |
$ | pretty = false , |
||
$ | escaping = 0 |
||
) | [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).
{ "id": "c41fb419", "file": "/var/www/mediawiki/includes/cache/MessageCache.php", "line": 704, "message": "Non-string key given", "url": "/wiki/Main_Page" }
{ "id": "dc457938", "file": "/vagrant/mediawiki/includes/cache/MessageCache.php", "line": 704, "message": "Non-string key given", "url": "/wiki/Main_Page", "backtrace": [{ "file": "/vagrant/mediawiki/extensions/VisualEditor/VisualEditor.hooks.php", "line": 80, "function": "get", "class": "MessageCache", "type": "->", "args": ["array"] }] }
Exception | $e | |
bool | $pretty | Add non-significant whitespace to improve readability (default: false). |
int | $escaping | Bitfield consisting of FormatJson::.*_OK class constants. |
Definition at line 320 of file MWExceptionHandler.php.
References array(), FormatJson\encode(), getRedactedTrace(), getURL(), and global.
Referenced by logException(), MWExceptionTest\testJsonserializeexceptionBacktracingDisabled(), MWExceptionTest\testJsonserializeexceptionBacktracingEnabled(), MWExceptionTest\testJsonserializeexceptionKeys(), and MWExceptionTest\testJsonSerializeExceptions().
static MWExceptionHandler::logException | ( | Exception $ | e | ) | [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 errors or errors from other libraries.
Exception | $e |
Definition at line 353 of file MWExceptionHandler.php.
References FormatJson\ALL_OK, getLogMessage(), global, jsonSerializeException(), and wfDebugLog().
Referenced by DeferredUpdates\doUpdates(), and MWException\report().
static MWExceptionHandler::printError | ( | $ | message | ) | [static] |
Print a message, if possible to STDERR.
Use this in command line mode only (see isCommandLine)
string | $message | Failure text |
Definition at line 94 of file MWExceptionHandler.php.
Referenced by report(), and MWException\report().
static MWExceptionHandler::report | ( | Exception $ | e | ) | [static, protected] |
Report an exception to the user.
Exception | $e |
Definition at line 37 of file MWExceptionHandler.php.
References getLogMessage(), getRedactedTraceAsString(), global, MWException\isCommandLine(), and printError().
Referenced by handle().
static MWExceptionHandler::rollbackMasterChangesAndLog | ( | Exception $ | e | ) | [static] |
If there are any open database transactions, roll them back and log the stack trace of the exception that should have been caught so the transaction could be aborted properly.
Exception | $e |
Definition at line 112 of file MWExceptionHandler.php.
References $factory, getLogMessage(), wfDebugLog(), and wfGetLBFactory().
Referenced by handle(), PublishStashedFileJob\run(), and AssembleUploadChunksJob\run().