2016-09-22 19:12:01 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Database
|
|
|
|
|
*/
|
2017-02-24 16:17:16 +00:00
|
|
|
|
|
|
|
|
namespace Wikimedia\Rdbms;
|
2016-09-22 19:12:01 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ingroup Database
|
2020-07-10 12:11:14 +00:00
|
|
|
* @newable
|
2020-07-13 09:00:30 +00:00
|
|
|
* @stable to extend
|
2016-09-22 19:12:01 +00:00
|
|
|
*/
|
|
|
|
|
class DBQueryError extends DBExpectedError {
|
|
|
|
|
/** @var string */
|
|
|
|
|
public $error;
|
2017-08-20 11:20:59 +00:00
|
|
|
/** @var int */
|
2016-09-22 19:12:01 +00:00
|
|
|
public $errno;
|
|
|
|
|
/** @var string */
|
|
|
|
|
public $sql;
|
|
|
|
|
/** @var string */
|
|
|
|
|
public $fname;
|
|
|
|
|
|
|
|
|
|
/**
|
2020-07-13 08:53:06 +00:00
|
|
|
* @stable to call
|
2016-09-22 19:12:01 +00:00
|
|
|
* @param IDatabase $db
|
|
|
|
|
* @param string $error
|
|
|
|
|
* @param int|string $errno
|
|
|
|
|
* @param string $sql
|
|
|
|
|
* @param string $fname
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $message Optional message, intended for subclases (optional)
|
2016-09-22 19:12:01 +00:00
|
|
|
*/
|
2017-09-18 11:38:59 +00:00
|
|
|
public function __construct( IDatabase $db, $error, $errno, $sql, $fname, $message = null ) {
|
|
|
|
|
if ( $message === null ) {
|
rdbms: Move "Did you forget…" from DBQueryError to MWExceptionHandler
This reminder, while useful to see on a web page during local
development or when live upgrading a small wiki, is not so
useful in error logs and production monitoring.
In addition to being general noise and boilerplate to have to
know to ignore (and to know where to look instead), it has the
unfortunate side-effect of letting the 255-char trimmed normalized
messages containing none of the actual errors.
Remove this from the DBQueryError exception message, and place
it instead in the code paths of:
* MWExceptionRenderer::getHTML, used when a fatal error
happens but we are still able to render it in a skinned
output page.
Test Plan:
- Edit SpecialBlankpage.php#execute, and add the following,
which involves a non-existant 'pagex' table:
$db = wfGetDB( DB_REPLICA );
$db->select( 'pagex', '1', 'foo = 2', __METHOD__ );
- View Special:Blankpage on your wiki
* MWExceptionRenderer::output (main 'else' branch), used
when a fatal error is unable to recover and thus render
a plain text HTML response.
Test Plan:
- Edit SpecialBlankpage.php#execute, and add the following,
which involves an SQL syntax error:
$db = wfGetDB( DB_REPLICA );
$db->select( 'page', '1', 'foo =/ 2', __METHOD__ );
- View Special:Blankpage on your wiki
Bug: T255202
Change-Id: Ie08199ced767486f9e049934a334a1438f266aa6
2020-06-11 22:08:33 +00:00
|
|
|
$message = "Error $errno: $error\n" .
|
2020-06-11 20:24:25 +00:00
|
|
|
"Function: $fname\n" .
|
rdbms: Move "Did you forget…" from DBQueryError to MWExceptionHandler
This reminder, while useful to see on a web page during local
development or when live upgrading a small wiki, is not so
useful in error logs and production monitoring.
In addition to being general noise and boilerplate to have to
know to ignore (and to know where to look instead), it has the
unfortunate side-effect of letting the 255-char trimmed normalized
messages containing none of the actual errors.
Remove this from the DBQueryError exception message, and place
it instead in the code paths of:
* MWExceptionRenderer::getHTML, used when a fatal error
happens but we are still able to render it in a skinned
output page.
Test Plan:
- Edit SpecialBlankpage.php#execute, and add the following,
which involves a non-existant 'pagex' table:
$db = wfGetDB( DB_REPLICA );
$db->select( 'pagex', '1', 'foo = 2', __METHOD__ );
- View Special:Blankpage on your wiki
* MWExceptionRenderer::output (main 'else' branch), used
when a fatal error is unable to recover and thus render
a plain text HTML response.
Test Plan:
- Edit SpecialBlankpage.php#execute, and add the following,
which involves an SQL syntax error:
$db = wfGetDB( DB_REPLICA );
$db->select( 'page', '1', 'foo =/ 2', __METHOD__ );
- View Special:Blankpage on your wiki
Bug: T255202
Change-Id: Ie08199ced767486f9e049934a334a1438f266aa6
2020-06-11 22:08:33 +00:00
|
|
|
"Query: $sql\n";
|
2016-09-22 19:12:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parent::__construct( $db, $message );
|
|
|
|
|
|
|
|
|
|
$this->error = $error;
|
|
|
|
|
$this->errno = $errno;
|
|
|
|
|
$this->sql = $sql;
|
|
|
|
|
$this->fname = $fname;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-24 16:17:16 +00:00
|
|
|
|
2018-05-29 16:21:31 +00:00
|
|
|
/**
|
|
|
|
|
* @deprecated since 1.29
|
|
|
|
|
*/
|
2017-02-24 16:17:16 +00:00
|
|
|
class_alias( DBQueryError::class, 'DBQueryError' );
|