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
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
* 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
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
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
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
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
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
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
And added/removed spaces around some other tokens,
like +, -, *, /, <, >, =, !
Fixed windows newline style
Change-Id: I0b9c8c408f3f6bfc0d685a074d7ec468fb848fc8
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
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
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
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
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
* 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
* 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
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
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
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
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
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
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
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
* 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