Commit graph

44 commits

Author SHA1 Message Date
Timo Tijhof
36e0e638a8 exception: No longer try to send error page post-send on api.php
For other endpoints this was already fixed, as all MWExceptionRenderer
logic checks headers_sent() before outputting headers.

For the MW_API condition, it was calling wfHttpError(), which in
turn unconditionally tried to send headers.

Fix this by removing use of wfHttpError(), and instead re-use the
existing logic for a minimal http error page. Do this by removing
the early condition and instead let if fall into the general
render methods, and then treat MW_API as a non-OutputPage scenario.

Bug: T225657
Change-Id: I38bbf8007078c290a2576ef177b789fab1d2059f
2020-03-26 17:53:27 +00:00
Umherirrender
3161311c5a Use MediaWikiServices::getMessageCache
Change-Id: I07fcc9529991adc634c10e5ed8498ac138a1c2b7
2020-03-14 14:25:03 +01:00
Ricordisamoa
1b3bc281ac Clean up redundant Exception|Throwable union type
PHP 7.0 makes many error conditions throw instances of the new Error class
which does not extend the known Exception.
The Throwable interface provides a concise and type-safe way of handling
either, e.g. for logging purposes, but HHVM did not support it, requiring
tedious fallback checks.

This commit replaces occurrences of Exception in code paths equally
covered by Throwable, like Exception|Throwable parameter and return types
(also nullable), instanceof guards, duplicated `catch` blocks, as well as
related comments and documentation blocks, with the exception of $previous
parameter descriptions consistent with the manual at
https://www.php.net/manual/en/exception.construct.php

Proper type declarations have been added or reinstated where possible.

Change-Id: I5d3920d3cc66936a350314e2f19c4f6faeffd7c0
2020-02-12 20:28:40 +00:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
Aaron Schulz
4f11b61454 Avoid using "enqueue" mode for deferred updates in doPostOutputShutdown
Set appropriate headers and flush the output as needed to avoid blocking
the client on post-send updates for the stock apache2 server scenario.
Several cases have bits of header logic to avoid delay:

a) basic GET/POST requests that succeed (e.g. HTTP 2XX)
b) requests that fail with errors (e.g. HTTP 500)
c) If-Modified-Since requests (e.g. HTTP 304)
d) HEAD requests

This last two still block on deferred updates, so schedulePostSendJobs()
does not trigger on them as a form of mitigation. Slow deferred updates
should only trigger on POST anyway (inline and redirect responses are
OK), so this should not be much of a problem.

Deprecate triggerJobs() and implement post-send job runs as a deferred.
This makes it easy to check for the existence of post-send updates by
calling DeferredUpdates::pendingUpdatesCount() after the pre-send stage.
Also, avoid running jobs on requests that had exceptions. Relatedly,
remove $mode option from restInPeace() and doPostOutputShutdown()
Only one caller was using the non-default options.

Bug: T206283
Change-Id: I2dd2b71f1ced0f4ef8b16ff41ffb23bb5b4c7028
2019-09-30 22:59:59 +00:00
Umherirrender
54190757bb Unpack arrays on variadic arguments
This avoids extra handling in the function to unpack an array

Change-Id: I93277599bc8125e23fca53d43a728fb7e9e39aad
2019-08-31 23:23:50 +00:00
Aryeh Gregor
7b4489e019 Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints.  This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases).  As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User.  If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args().  Some of the changes are definitely safe, like
functions and test classes.

In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:

* Forwarding all arguments to another function. It's useful to keep
  func_get_args() here where we want to keep the list of expected
  arguments and their meanings in the function signature line for
  documentation purposes, but don't want to copy-paste a long line of
  argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
  arguments individually but want to use them as an array as well for
  some reason.

Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2019-04-12 20:17:01 +00:00
Reedy
c13fee87d4 Collapse some nested if statements
Change-Id: I9a97325d738d09370d29d35d5254bc0dadc57ff4
2019-04-04 19:02:22 +00:00
Brian Wolff
d5dd48b8a6 Various fixes to make phan-taint-check happier
Bug: T216348
Change-Id: Ice672eed3b7e4a199e1307a6477ffe31502b97b5
2019-03-02 23:49:24 +00:00
Juan Osorio
1d930860cc Removes Google web search from exception page
When a wiki is down, it is not necessarily useful to be able to
search the web. Additionally, there is general consensus that
the hard-coded Google search form should be removed.

Bug: T208871
Change-Id: I5bcae848de1144d4fc1116c475b2e2ab1ccc3f7d
2018-11-13 15:47:42 +00:00
Fomafix
1472f02b36 Phabricator: Use Tddddd instead of Bug ddddd in comments
Change-Id: Ic9fe03cab270bd6be738af346164ad5d31a0d780
2018-10-04 09:15:02 +02:00
Timo Tijhof
9512ebe736 exception: Add FIXME about code duplication
These methods aren't identical, so consolidation isn't
immediately obvious, and creating dependencies is problematic
in error handling code given there is a lot of pressure on this
code to not by itself cause additional errors.

This means that maybe it's best to keep these inlined without
duplication, but at the very least we then need to remember
to keep these in sync. This duplication has been around for
a while now, but documentation can never come too late...

Change-Id: I60160f61c13c8e115d839acce222f110e30bc2f2
2018-09-28 22:17:07 +00:00
Timo Tijhof
8476ec3cb8 exception: Avoid preg_replace for literal swap
Follows-up bbcbcaba3d.

Change-Id: Ie7b76c28ba53668d73a8435c4d2ec91757bd2372
2018-09-27 17:39:42 +01:00
Brian Wolff
bbcbcaba3d Fix html <title> for exceptions during message parsing.
Previously an ugly {{SITENAME}} would show up for exceptions
that happened in the middle of processing a message

Change-Id: I4e3b675673dc3b74f89e4325f6a0a8b44162f478
2018-09-01 20:19:45 +00:00
Bill Pirkle
807125abdb Deprecate $wgShowSQLErrors and $wgShowDBErrorBacktrace and make nonfunctional
Clarify and simplify exception output by deprecating
$wgShowSQLErrors and wgShowDBErrorBacktrace.
$wgShowExceptionDetails will now control most related output.
$wgShowHostnames will now solely control output of
MWExceptionRenderer::reportOutageHTML.

Bug: T165768
Change-Id: Idead2c11c499463dfa6293c3d4b33be3bde92e1a
2018-07-25 10:38:19 -05:00
Strainu
94b58b2c26 MWExceptionRenderer: Fix db error outage page
Set content encoding and add some content to the header tag.

Bug: T195525
Change-Id: Ieabfe18280359459e9462204371d3fe8d62a4177
2018-06-15 22:21:16 +02:00
Umherirrender
3124a990a2 Use ::class to resolve class names in includes files
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: I07a925c2a9404b0865e8a8703864ded9d14aa769
2018-01-27 20:34:29 +01:00
jenkins-bot
9219588de6 Merge "MWExceptionRenderer: Wrap error message in a paragraph" 2017-11-15 10:38:43 +00:00
Brian Wolff
fea3bbcdae SECURITY: Escape internal error message
This message contains the request url, which is semi-user controlled.
Most browsers percent escape < and > so its probably not exploitable
(curl is an exception here), but nonetheless its not good.

Bug: T178451
Change-Id: I19358471ddf1b28377aad8e0fb54797c817bb6f6
2017-11-15 00:58:44 +00:00
Bartosz Dziewoński
7e3f457e80 MWExceptionRenderer: Wrap error message in a paragraph
Bug: T180284
Change-Id: I71563fd6932d35c7298b185bd7c05c8f1dce63f8
2017-11-13 13:39:53 +01:00
Umherirrender
3f1a52805e Use short type bool/int in param documentation
Enable the phpcs sniffs for this and used phpcbf

Change-Id: Iaa36687154ddd2bf663b9dd519f5c99409d37925
2017-08-20 13:20:59 +02:00
jenkins-bot
06d611a399 Merge "Remove newline at end of MWExceptionRenderer::getShowBacktraceError" 2017-07-18 19:23:40 +00:00
Fomafix
6d0111186f Remove newline at end of MWExceptionRenderer::getShowBacktraceError
Also add a period at the end of the sentence.

This changes the HTML comment from

<!-- Set $wgShowExceptionDetails = true; at the bottom
of LocalSettings.php to show detailed debugging
information
 -->

to

<!-- Set $wgShowExceptionDetails = true; at the bottom
of LocalSettings.php to show detailed debugging
information. -->

This is a follow-up to 842b7a1769 (T162315).

Change-Id: I45ff4f856ad1c0dc72066fce7771077ff4663785
2017-07-18 12:26:44 +02:00
Fomafix
15fb994130 Avoid double HTML encoding
Html:element() already makes an HTML encoding. The additional
htmlspecialchars is not necessary.

Change-Id: If0530c3d3cb0d3cc61e849a1c84ae0d68c242517
2017-07-03 17:55:15 +02:00
Aaron Schulz
82e2c924e4 Remove "@author Aaron Schulz" annotations
Bug: T139301
Change-Id: Ib5248e8e27d60611c7373bce4b29dd5e85aa3489
2017-06-27 15:24:14 -07:00
Alex Monk
f8b8d2689d MWExceptionRenderer::useOutputPage: Don't bother if we have no Title context
Change-Id: Ieb6d682a9f2fb4def4c01908ccd035fcce2e1895
2017-05-31 22:52:46 +00:00
Gergő Tisza
fcd495ffef Remove $wgExceptionHooks
Skip deprecation period because it is very unlikely that anyone used this:
it does not appear anywhere on gerrit/git, no nontrivial google hits,
the documentation has been flat out wrong for 9 years and no one
noticed it, and the whole feature is fairly useless as you need to declare
it separately for every single exception class you expect.

Change-Id: I85844a238d3135d05eeba10331149624b04bafe2
2017-05-22 00:57:44 +02:00
jenkins-bot
2ecb96a96f Merge "exception: Add newline at the end of a debugging line for CLI users" 2017-04-26 21:35:33 +00:00
Florian Schmidt
842b7a1769 exception: Add newline at the end of a debugging line for CLI users
Bug: T162315
Change-Id: Ia2963fa298ab0e4782ef823e7f53322cd6a9c99b
2017-04-26 21:26:13 +00:00
jenkins-bot
2d71bf187d Merge "Send 500 http status code, instead of 200, for DBConnectionErrors" 2017-04-22 02:08:09 +00:00
Florian Schmidt
2c1dc398be Send 500 http status code, instead of 200, for DBConnectionErrors
Bug: T160875
Change-Id: I4c909457938a19358dfc4b2aec216b1a148df46c
2017-04-21 11:55:36 +00:00
Aaron Schulz
dd359741cc Move DB errors to Rdbms namespace
Change-Id: I463bd86123501abc68fdb78b4cda6110f7af2549
2017-04-15 10:47:41 -07:00
Huji Lee
0136242734 Always show exceptions of type 'error' in LTR
Bug: T153027
Change-Id: Iad5b9a01f5b8cdaa2ed94b3ece937acc1f6faa60
2016-12-12 20:23:41 -05:00
Aaron Schulz
0a615dd414 Include getPublicLogMessage() in double-exception messages
Change-Id: I364e237f859d65fdcc29025c63c90ac2e0b96718
2016-11-21 22:18:53 -08:00
jenkins-bot
5433c9357d Merge "Replace wgShowExceptionDetails with wgShowDBErrorBacktrace on db errors" 2016-11-21 22:27:38 +00:00
Reedy
57a1e7b270 Replace wgShowExceptionDetails with wgShowDBErrorBacktrace on db errors
Bug: T148957
Change-Id: I8891369156547e8931463a2fd55995cfa9e98ee7
2016-11-21 22:07:03 +00:00
Chad Horohoe
524e624637 Exception renderer: Remove useless check for isCommandLine()
If we're on the cli, we would've never hit this else block

Change-Id: Idff009ab255b1907f752e0c6b5652715923b0ed7
2016-11-21 13:47:09 -08:00
Aaron Schulz
97b5aa9a11 Exception rendering fixes
* Actually use MWExceptionRenderer::AS_RAW. Use this after
  an error is thrown while trying to pretty render the original
  error. This is how this case was originally handled before.
* Do not show the google form or file cache in CLI mode.

Change-Id: I130499753efbf8b4d6d254ea36bacb2473952c1b
2016-09-30 16:57:48 -07:00
Max Semenik
2b51bd1847 Fix function name case
Change-Id: Ibd4f682d2ed8500a50d85aae38f17281646f7c2d
2016-09-26 15:32:54 -07:00
Aaron Schulz
cb9901ef41 Fix "MWExceptionRenderer::getText() should not be called statically" errors
Change-Id: Icfb65795b1455217ca9bc2c1f7cd453144ad5106
2016-09-19 10:55:10 -07:00
Brad Jorsch
0b93d767ea Make MWExceptionRenderer work with PHP7's exception changes
See https://wiki.php.net/rfc/throwable-interface

Change-Id: Ib65f912580f5d84997c5926e7f602d5f5ef3faba
2016-09-19 12:40:36 -04:00
Aaron Schulz
3ad9e41be9 Fix $wgFileCache DB outage fallback
Change-Id: I5c41b4669ca29d119de5c08a2c61dbadae7cf55c
2016-09-16 02:18:12 +00:00
Aaron Schulz
5820c6dcac Exception cleanups for LoadBalancer
* Make the error message itself be dumb/raw.
* Make the exception exposer show the same GUI message.
* Remove overzelous wgLang check in MWExceptionRenderer.

Change-Id: Ifffff3b3cc785ea3080e4975efe33b3c2cf304d6
2016-09-15 01:32:43 +00:00
Aaron Schulz
00bee02971 Add MWExceptionRenderer class and decouple DBError
* This handles the work of showing exceptions so that
  MWException does not have too.
* Simplify the DBError classes to regular Exception
  classes. Lots of pointless prettification has been
  removed, but DBConnectionError still gets the usual
  special treatment of a fallback page and Google form.
* Remove hacky file cache fallback code that probably
  did not work.
* Make MWExceptionHandler::report() wrap
  MWExceptionExposer::output().
* Make MWException::runHooks() wrap
  MWExceptionExposer::runHooks().

Change-Id: I5dfdc84e94ddac65417226cf7c84513ebb9f9faa
2016-09-14 11:53:55 -07:00