Commit graph

130 commits

Author SHA1 Message Date
Ori Livneh
4ae6be7f92 Log JSON-formatted exceptions to 'exception-json' log bucket
Much of the original scope of this patch has been made redundant by other
patches, so it's nice and compact now. This patch makes MediaWiki serialize
exceptions to JSON and log them to an 'exception-json' log group.

To facilitate this, two related changes are included:

* Consolidated the code for annotating the exception with the request URL (if
  the exception was encountered while responding to a request) in a method,
  Exception->getURL.

* Removed the code path that checked for a falsey return value from
  $wgRequest->getRequestURL() and set the url to '[no URL]'. ('[no req]' is
  retained.) Nowadays getRequestURL() always returns a string (or throws an
  exception). Wikimedia's cluster doesn't have a single '[no URL]' in its log
  archives, which go back several months.

Change-Id: Iacda90fb401f6a45ed1ac1a991e0884663e6c0bf
2013-11-05 12:40:24 -08:00
Brad Jorsch
451599d812 MWException: Cleanup exception message output
Change I0a9e9244 lost the message when handling a non-MWException
exception, and for a long time MWException's getHTML and getText have
been missing the actual file and line where the exception was thrown.

We may as well use MWExceptionHandler::getLogMessage to fix all of
these, resulting in a more standardized exception output.

Change-Id: I8a9b4831c9c586bafe0a54516ff779cdfb008984
2013-11-01 14:46:19 -04:00
Antoine Musso
0ee7ea85d0 redact exception traces and abstract getTrace
* Partially reverts I0a9e92448 (rationale:
   http://www.gossamer-threads.com/lists/wiki/wikitech/401558)
  - wfDebugLog()'d exceptions are always unredacted
  - Other backtraces are redacted by replacing all argument values with class /
    type names.
* Adds a pair of static methods to MWExceptionHandler:
  - MWExceptionHandler::getRedactedTrace
	equivalent to Exception::getTrace, but replaces each argument value
	in the trace with its class or type name.
  - MWExceptionHandler::getRedactedTraceAsString
    equivalent to Exception::getTraceAsString, but with argument values
	likewise redacted.
* The rename of 'formatRedactedTrace' to 'getRedactedTraceAsString' is
  justified on two grounds:
  - 'formatRedactedTrace' didn't actually take a trace object (it took an
	exception).
  - 'getRedactedTraceAsString' maintains the symmetry with
    Exception::getTraceAsString.

Change-Id: I3d570a6385f96a606e1af53c50faa03b9ebacd38
2013-11-01 11:07:18 -07:00
Siebrand Mazeland
e61cb8218b Update docs and declare visibility on class props
Change-Id: Ib0f02202d075d4a56dc4e37b08d7ac9399e8c86c
2013-11-01 12:35:27 +01:00
Timo Tijhof
4468a46af2 exception: Use MWExceptionHandler::logException in more places
Most code replaced wasn't exactly like what logException does
but most probably should be.

A few implementation differences with the code it replaced in
various places:

* MWException if-guards
  Was there only to prevent a crash because getLogMessage is an
  MWException method. Now that logException is generic, it seems
  sensible to start logging those as well (follows-up a97f3550a0).

* Exception::getTraceAsString
  Now using MWExceptionHandler::formatRedactedTrace instead.
  It wasn't using it because that method didn't exist yet.

Notes:

* DatabaseError::getLogMessage
  Removed as this override was no longer doing anything (we're using
  MWExceptionHandler::getLogMessage instead of $e->getLogMessage).
  Introduced isLoggable() to take over the responsibility of indicating
  when an exception should not be logged (follows-up bcb9f9e1c0).

* DeferredUpdates and Wiki.php
  Both specificy MWException. Though ApiMain intends to catch all
  and only logged MWException because it couldn't otherwise, these
  actually only catch MWException (as opposed to catching all and
  having an if-statement inside). Left those as-is to have them
  continue propagate other exceptions.

* JobQueueFederated and JobQueueGroup
  All specify to catch JobQueueError only.
  Not sure whether it should catch other exceptions. It now can,
  but I'll leave it as is in case it intends to have those be
  handled elsewhere (or fatal).

Change-Id: I4578a0fe7d95a080f1a3b292ce7ae73a4d5fcaca
2013-10-30 15:46:35 -07:00
Timo Tijhof
2bcffe8be4 Exception: Clean up html document for error pages
Interface:
* Restore sitename as part of error page document title
  (follows-up 4ca9805). Moved to general Exception class as it
  is useful in general, this effectively changes the title from
  "This wiki has a problem" to "Internal error - Wikipedia".
* Added basic <style> to have it use a sans-serif font and a bit
  padding to offset it from the edge of the window.
* Output stacktrace in <pre> as-is (with linebreaks) instead of
  in a <p> with <br/>.

Clean up:
* Removed spurious "<!-- SiteSearch Google -->" comment.
* Change sitesearch radio button to not need the id/for
  attributes but simply nest them. Visual rendering and browser
  behaviour is identical.
* Renamed $text to $html since that is what it is (follows-up
  4ca9805 which reused that variable for html, it used to contain
  text).
* Remove odd linebreak from "dberr-problems" message, it was
  being output as-is in the html (html escaped, of course) and
  line breaks have no meaning inside an <h1> tag. Using a simple
  space instead. Visual rendering is identical.

Coding style:
* Using <!DOCTYPE html> instead of <!doctype html> for consistency
  with other documents we output.
* Switched a few inline #-style comments to use // instead.
* Switched a few strings from double quotes to single quotes in
  areas close to the changed code.

Change-Id: I33232d871200cbd23501c9a6c5f8a178931e135e
2013-10-30 21:52:49 +00:00
Brad Jorsch
63b2441d62 Distinguish redactions from the string "REDACTED" in formatRedactedTrace
In the output of MWExceptionHandler::formatRedactedTrace, it is not
possible to determine (without checking the configuration) whether arg 0
in "foo('REDACTED')" was redacted or was merely passed the string
"REDACTED".

This patch changes redaction to instead output "foo(REDACTED)" in the
case of redaction. This parallels the situation with arrays and objects,
where for example "foo(Array)" was passed an array while "foo('Array')"
was passed the string "Array".

Change-Id: Ia2a761687c69b630afa3ccd8668b06b28e3ecdd3
2013-10-25 11:42:27 -04:00
Timo Tijhof
f0386d3183 exception: Move logging logic to static method of MWExceptionHandler
Follows-up c28251a9fd, which unconditionally called logException
on objects that aren't always instances of MWException.

This makes it possible to, for example, log PHP errors or errors
from Less in ResourceLoader to be logged as well (which naturally
don't have a logException method).

As a result of the handling now being generic, non-MWException
errors will now be loggable, and also have their ID fixed between
HTML output and the debug log entry.

* Not yet removing MWException::getLogMessage (introduced in bcb9f9e1c)
  as it has been around since 2006 (released in 1.8.0).

* Not yet removing MWException::getLogId (introduced in 70841c5867)
  as it was part of the 1.20.0 release.

* Removed MWException::logException (introduced in c28251a9fd)
  as it was only added a few weeks ago within this release cycle.

Change-Id: Iab98e3a7a9b78d8602e69e0571b35cf107a96b72
2013-10-14 05:00:40 +00:00
Kevin Israel
b82259ee39 Ensure that $call['args'] is set before using it
Fixes PHP Notice:  Undefined index: args in /home/ki/Projects/mediawiki/
core/includes/Exception.php on line 755 when running code from
maintenance/eval.php .

Change-Id: Ic4a806232aadae0a60f5bc06de1604d9c5996e6f
2013-10-13 10:31:06 -04:00
Timo Tijhof
3ca7f919e0 exception: Account for $call['file'] and $call['line'] being unset
Bug: 55634
Change-Id: I1173216cade73216848816f6bb51e54096abdfde
2013-10-11 20:42:55 +02:00
Alex Monk
459cb0b7bb Add a way to redact certain function parameters from exception stack traces
Bug: 30714
Change-Id: I0a9e92448f8d9009dd594cb4d7f5dc6fdd4bcc86
2013-09-21 02:09:02 +00:00
Aaron Schulz
c28251a9fd Fully log exceptions within ResourceLoader (including traces)
Change-Id: Icb479c76cd855244429fe65b29667783dcca8f53
2013-09-18 16:30:18 +00:00
umherirrender
21751b9ba7 echo is not a function
Removed parenthesis after echo

Change-Id: Ia533aedf63b11d15dcc6a5cf75a56134a4b11d86
2013-05-09 19:52:45 +00:00
Kevin Israel
47d1060398 Remove is_numeric check from Title::checkUserBlock
This should allow the usernames of administrators such as "7"
to show correctly on permissions error pages.

I extracted the working code from UserBlockedError::__construct
into a separate method Block::getPermissionsError, called from
both places with context provided as an argument.

Additional changes to get the test suite to pass are included.

Bug: 46768
Change-Id: I49d973992a99e03b4e8de112b47b737037a85338
2013-04-24 01:05:23 +00:00
umherirrender
ef2f507d23 Fixed spacing in files direct in includes folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: Ibb8dd102db045522d12ff939075ba7420d95ab6b
2013-04-21 06:38:49 +00:00
umherirrender
15abcf71ca Added/Removed spaces around string concatenation
And added/removed spaces around some other tokens,
like +, -, *, /, <, >, =, !

Fixed windows newline style

Change-Id: I0b9c8c408f3f6bfc0d685a074d7ec468fb848fc8
2013-04-13 13:36:24 +02:00
Timo Tijhof
acb292d733 phpcs: Fix Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore violations
ERROR: Closing brace must be on a line by itself
Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore

- For non-empty scopes it means the closing brace must be on a separate
  line. This is already the case in most classes in some cases the "lazy
  closing" is still used.
  array(
   'x' ); // Moved } to next line
  function () { return 'x'; } // Moved } to next line
  case 1:
    stuff; break; // Moved break to next line
- For empty function it serves as a visual distinction between there not
  being a scope block / function body and there being an empty function
  body.
  function foo(); // No body
  function foo() {} // Empty body - violation
  function bar() { // Empty body corrected
  }

Change-Id: I0310ec379c6d41cc7d483671994d027a49f32164
2013-04-11 07:34:41 +00:00
Hashar
572ee81c0b Revert "Remove is_numeric check from Title::checkUserBlock"
Breaks unit testing (see bug 47031). The commit managed to land in
the branch because of a bug in Jenkins (bug 46723).

This reverts commit 8cc0b601aa

Change-Id: I4b3fadccaae9c35964a0c47d63b22c4f35148a24
2013-04-09 08:20:12 +00:00
Kevin Israel
8cc0b601aa Remove is_numeric check from Title::checkUserBlock
This should allow the usernames of administrators such as "7"
to show correctly on permissions error pages.

I extracted the working code from UserBlockedError::__construct
into a separate method Block::getPermissionsError, called from
both places with context provided as an argument.

Bug: 46768
Change-Id: Ic3fa926a5a4c109faff35fffbccb60fb06ea4a18
2013-04-09 02:40:35 +00:00
Platonides
29f713ed10 Specify the utf-8 charset on error messages.
Although the contents of error messages are English text,
and thus it's irrelevant that it gets interpreted as
iso-8859-1 instead of utf-8, $wgSitename is printed by
DBConnectionError::searchForm(), and that can contain utf-8.

Cached pages may also be in utf-8.

Change-Id: I81c02493f0824cb010c80f4356f338787d78df6b
2013-04-04 01:28:33 +02:00
Brad Jorsch
fb04d38e23 (bug 44111) ErrorPageError log messages should be in English
We want log messages to be in English. ErrorPageError, however, will log
the messages using the language of the current user. This isn't often
noticed, because the normal page view code path doesn't log
ErrorPageError and the API doesn't usually have ErrorPageError thrown in
the first place.

The fix is simple enough: in the constructor, create a new Message
object and call ->inLanguage( 'en' ) on it. And, for good measure,
->useDatabase( false ) so customizations on the local wiki won't show up
in the log files either.

Since ErrorPageError already overrides report(), that will take care of
still showing the expected language to the end user.

Bug: 44111
Change-Id: I9a6ab43d63e76fa9708b62e32ddc3262aff282f7
2013-03-28 02:39:05 +00:00
umherirrender
6c278b6d7e fix some spacing
* Removed spaces around array index
* Removed double spaces or added spaces to begin or end of function
  calls, method signature, conditions or foreachs
* Added braces to one-line ifs
* Changed multi line conditions to one line conditions
* Realigned some arrays

Change-Id: Ia04d2a99d663b07101013c2d53b3b2e872fd9cc3
2013-03-25 22:22:46 +00:00
Yuri Astrakhan
9506e3d812 Spellchecked /includes directory
* Ran spell-checker over code comments in /includes/
* A few spellchecking fixes for wfDebug() calls

Found one very strange (NOOP?) line in Linker.php - see "TODO: BUG?"

Change-Id: Ibb86b51073b980eda9ecce2cf0b8dd33f058adbf
2013-03-13 03:42:41 -04:00
Tyler Anthony Romeo
4dcc7961df Fixed @param tags to conform with Doxygen format.
Doxygen expects parameter types to come before the
parameter name in @param tags. Used a quick regex
to switch everything around where possible. This
only fixes cases where a primitve variable (or a
primitive followed by other types) is the variable
type. Other cases will need to be fixed manually.

Change-Id: Ic59fd20856eb0489d70f3469a56ebce0efb3db13
2013-03-11 13:15:01 -04:00
umherirrender
d63121016d fix some spacing
Added/removed spaces around logical/arithmetic operator
Reduced multiple empty lines to one empty line
Removed wrong tabs before comments at end of line
Removed too many spaces in assigments

Change-Id: I2bba4e72f9b5f88c53324d7b70e6042f1aad8f6b
2013-03-07 17:53:21 +01:00
umherirrender
1044b0b8df fix some spacing
Change-Id: I8f976013f33c5818e4402604fe8610aa3f43b0c6
2013-02-04 20:18:33 +00:00
daniel
8e7f3b79d7 Add return to HttpError::getStatusCode.
Oops...

Change-Id: I4fb5bd11be340870d903d62e1329b1181f72e695
2013-02-01 16:17:38 +01:00
daniel
2e8e4478af Add getters to HttpError, to use it in tests.
Change-Id: I1165063ebdbcc29ae26998bd6ab74782dc0ecdc5
2013-01-30 22:45:32 +01:00
daniel
7448da5ddc Make HttpError set actual HTTP error code.
Previsouly, HttpError would set a Status header with the desired code,
but would not change the actual HTTP/1.1 header to include that code.

Change-Id: I2f68b1fa410b3619c5be3e82b64f99df97b9415a
2013-01-29 17:02:19 +01:00
umherirrender
6fbbbd17ca fix some spacing
Change-Id: Ie7bb35871cc99237f3a655f7db22ca1f0646df5e
2013-01-27 14:21:50 +01:00
S Page
755d9563c6 Typo in comment's Example code.
Patch 2: fix both comment Examples, rephrase comment, fix a few typos.

Change-Id: Id57d9307a3f613445faacdea8c9a4e195ad3987d
2012-11-26 21:23:40 -08:00
Alexandre Emsenhuber
2393a58ddc Don't exit too quickly when reporting an exception.
MWExceptionHander::handle() already exist at the end of its task,
so there's no need to have other die() calls.

There were some problems with that:
- wfLogProfilingData() was only called after reporting some exception
- MWExceptionHandler::report() was not consistent between web and
  command-linerequests
- MWException::reportHTML() was also not consistent when using the
  OutputPage object or not

Also removed MWExceptionHander::escapeEchoAndDie() since it's not needed anymore.

Change-Id: Ibb679c425ef0271a65f623c7b8541ec9bec70eb0
2012-09-09 15:12:02 +02:00
Siebrand Mazeland
c6b74865fe Fix documentation.
Change-Id: I43f4ae1248bc4a24cf127fadb6e616da8d4516e2
2012-08-27 11:48:47 +02:00
Siebrand Mazeland
6fe1f0509b Replace deprecated wfMsg* calls with Message class calls.
Doing this in steps of roughly 100 changes per commit, so that it remains reviewable.

Change-Id: Ib15e670badd3f6aecae8b60e2f9129a31341ce16
2012-08-21 18:38:44 +02:00
Siebrand Mazeland
9ff9aaae63 Fix typo: occured -> occurred.
Change-Id: I5e66fdd52791487f81796ae1965ac31c94b36182
2012-08-10 10:59:55 +02:00
Alexandre Emsenhuber
0b2d671d2c @since to subclasses of MWException
Change-Id: I9f87ba2ab00e4a68313a19823a20b10d55073e84
2012-08-02 10:36:56 +02:00
Alexandre Emsenhuber
ae927637d3 Documentation improvements in Exception.php.
Change-Id: I645025c9acbb91df48bb0f1ee3859840195c5e56
2012-07-12 21:59:14 +02:00
Alexandre Emsenhuber
bc470f3661 Send correct HTML when reporting a MWException object and the OuputPage object cannot be used.
Currently only the body was sent, without doc type, <html>, <head> or <body> items.

Change-Id: I2d5cc3f69f55d0e1b212148f57f736f100bd2554
2012-07-06 20:57:12 +02:00
Antoine Musso
b1c1448d98 (bug 37627) generic exception for not logged in users
We have various place in MediaWiki core and in extensions which are
showing anonymous user a very standard error page about them not being
logged in. Each developer ends up writing its own because we do not
provide a generic error, that is what this patch does.

This UserNotLoggedIn exception, when called, will show the usual
ErrorPage with a default title and default reason text. That makes it as
easy to use as doing:

 if( $user->isAnon() ) {
 	throw new UserNotLoggedIn();
 }

One can override the default reason by passing a message key as the
first parameter:

 if( $user->isAnon() ) {
 	throw new UserNotLoggedIn( 'nologin-reason-text' );
 }

In that case, the page title will still be the default 'Not Logged In.'

Change-Id: Id81272995627bf0f5bbef785230a8e6e4e8582ca
2012-06-26 16:03:42 +02:00
Antoine Musso
af4b004485 document ErrorPageError constructor parameters
ErrorPageError can receive either a message object or a message key

Change-Id: I8e51d802c2ab333fd61069a713c39dda0f418232
2012-06-26 16:00:54 +02:00
awjrichards
c29fd59775 Big oops - merged to wrong branch.
Revert "Revert to arbitrarily old point before initial remote branch creation to help clean up"

This reverts commit ee0d3d330f
2012-06-05 22:58:54 +00:00
awjrichards
ee0d3d330f Revert to arbitrarily old point before initial remote branch creation to help clean up
Change-Id: I41a3d1e55d3ea9dffa42451237fe065f9334361d
2012-06-02 08:43:04 -07:00
Platonides
3e59f15bb0 Set the status code to 500 on exceptions.
Should fix bug 37140, scripts served through
action=raw failing due to being served a html
error page.
As well as such as giving a better behavior
such as for search engines.
This could affect IE users by showing them
smart errors instead of the content, though.

Change-Id: I5d680fe10db6d61d91e898323bd5fb755a07135d
2012-05-31 19:15:33 +02:00
Alexandre Emsenhuber
3bbda787b8 Added missing GPLv2 headers in some places.
Also made file/class documentation more consistent.

Change-Id: Ic1ba00472ef62fa4fd746f8f590fe694d490ecd9
2012-05-20 17:56:43 +02:00
Tim Starling
e2aa8b4978 Don't log HttpError
Fix for r97314: don't log HttpError exceptions to the exception log channel. Do
this by overriding MWException::report() rather than
MWException::reportHTML(), same as every other child class in
Exception.php.

Change-Id: I3fb2b0ca9b0e7c67c210078d1fd90e1430be39df
2012-05-15 15:04:40 +10:00
Tim Starling
70841c5867 Make $wgShowExceptionDetails=false more feasible for production
* Make the HTML error message prettier, with a nice red box and
  instructions to modify LocalSettings.php hidden in an HTML comment.
* Show the exception class name, since that's pretty safe.
* Show a random "log ID" to the user, and also send it to the exception
  log, to allow easier log correlation.
* Optionally send backtraces to the error log, enabled by default.

Change-Id: Ie92e46032b3d194c4217119567847a38a53be577
2012-05-08 10:01:13 +10:00
Reedy
2edbe14e39 Normalising return statements
Add/improve parameter documentation

Change-Id: I4c7fa319be60a47b7fcd81131458577bccb009fb
2012-04-27 16:40:14 +01:00
Antoine Musso
6d915be35f update html DOCTYPE sent by HttpError exception
Follow up r110486, which updated doctype sent by wfHttpError()

Change-Id: I0e89420dd95edcf1ac76e3984b36f92df11cdb3f
2012-04-20 14:55:23 +02:00
Reedy
8c84c3879b parent::report() returns nothing, so don't attempt to return its value
Change-Id: Id506d51818bf101a68fe8b028df2062ed221cdf9
2012-04-07 19:39:43 +01:00
Max Semenik
d3e0e88f18 Don't output skinned errors in case of unhandled API exceptions 2012-02-20 19:19:52 +00:00