MediaWiki  REL1_24
MWExceptionHandler Class Reference

Handler class for MWExceptions. More...

List of all members.

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.

Detailed Description

Handler class for MWExceptions.

Definition at line 25 of file MWExceptionHandler.php.


Member Function Documentation

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.

Since:
1.22
Parameters:
Exception$e
Returns:
string

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.

Since:
1.22
Parameters:
Exception$e
Returns:
string

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).

Since:
1.22
Parameters:
Exception$e
Returns:
array

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.

Parameters:
Exception$e
Returns:
string

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.

Since:
1.23
Returns:
string|bool

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(); }

Parameters:
Exception$e

Definition at line 136 of file MWExceptionHandler.php.

References $e, $wgFullyInitialised, global, report(), rollbackMasterChangesAndLog(), and wfLogProfilingData().

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).

Sample JSON record ($wgLogExceptionBacktrace = false):
  {
    "id": "c41fb419",
    "file": "/var/www/mediawiki/includes/cache/MessageCache.php",
    "line": 704,
    "message": "Non-string key given",
    "url": "/wiki/Main_Page"
  }
Sample JSON record ($wgLogExceptionBacktrace = true):
  {
    "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"]
    }]
  }
Since:
1.23
Parameters:
Exception$e
bool$prettyAdd non-significant whitespace to improve readability (default: false).
int$escapingBitfield consisting of FormatJson::.*_OK class constants.
Returns:
string|bool JSON string if successful; false upon failure

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.

Since:
1.22
Parameters:
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)

Parameters:
string$messageFailure 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.

Parameters:
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.

Since:
1.23
Parameters:
Exception$e

Definition at line 112 of file MWExceptionHandler.php.

References $factory, getLogMessage(), wfDebugLog(), and wfGetLBFactory().

Referenced by handle(), PublishStashedFileJob\run(), and AssembleUploadChunksJob\run().


The documentation for this class was generated from the following file: