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
This commit is contained in:
parent
5b7e86df0c
commit
6d689330c6
2 changed files with 13 additions and 4 deletions
|
|
@ -22,6 +22,7 @@ use MediaWiki\Logger\LoggerFactory;
|
|||
use MediaWiki\MediaWikiServices;
|
||||
use Psr\Log\LogLevel;
|
||||
use Wikimedia\Rdbms\DBError;
|
||||
use Wikimedia\Rdbms\DBQueryError;
|
||||
|
||||
/**
|
||||
* Handler class for MWExceptions
|
||||
|
|
@ -450,6 +451,10 @@ TXT;
|
|||
/**
|
||||
* Get a message formatting the throwable message and its origin.
|
||||
*
|
||||
* Despite the method name, this is not used for logging.
|
||||
* It is only used for HTML or CLI output, by MWExceptionRenderer
|
||||
* and MWException::getText, respectively.
|
||||
*
|
||||
* @since 1.22
|
||||
* @param Throwable $e
|
||||
* @return string
|
||||
|
|
@ -462,6 +467,12 @@ TXT;
|
|||
$message = $e->getMessage();
|
||||
$url = self::getURL() ?: '[no req]';
|
||||
|
||||
if ( $e instanceof DBQueryError ) {
|
||||
$message = "A database query error has occurred. Did you forget to run"
|
||||
. " your application's database schema updater after upgrading?\n\n"
|
||||
. $message;
|
||||
}
|
||||
|
||||
return "[$id] $url $type from line $line of $file: $message";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,11 +44,9 @@ class DBQueryError extends DBExpectedError {
|
|||
*/
|
||||
public function __construct( IDatabase $db, $error, $errno, $sql, $fname, $message = null ) {
|
||||
if ( $message === null ) {
|
||||
$message = "A database query error has occurred. Did you forget to run " .
|
||||
"your application's database schema updater after upgrading? \n" .
|
||||
"Query: $sql\n" .
|
||||
$message = "Error $errno: $error\n" .
|
||||
"Function: $fname\n" .
|
||||
"Error: $errno $error\n";
|
||||
"Query: $sql\n";
|
||||
}
|
||||
|
||||
parent::__construct( $db, $message );
|
||||
|
|
|
|||
Loading…
Reference in a new issue