Skip to content

Commit

Permalink
PLATFORM-9121 | Do not swallow DB errors in Cargo query
Browse files Browse the repository at this point in the history
Cargo currently swallows all exceptions thrown while it is running
queries, mainly because it may throw MWExceptions as validation errors
which should be formatted nicely without breaking the rest of the page.
However, the queries themselves may fail due to transient database
issues, and Cargo wraps the resulting DBError exceptions as well without
much ado. The effect is that these errors never get logged (so we don't
even know how often this happens), and the error gets cached in parser
cache and on the CDN, forcing people to check for and periodically purge
pages with such errors.

Instead, detect and rethrow errors coming from MediaWiki's DBAL so that
we can track them in our logs, and so that they do not get cached.
  • Loading branch information
mszabo-wikia committed Mar 5, 2024
1 parent 952a358 commit 3e29ed7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions includes/CargoLuaLibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function cargoQuery( $tables, $fields, $args ): array {
$query = CargoSQLQuery::newFromValues( $tables, $fields, $where, $join,
$groupBy, $having, $orderBy, $limit, $offset );
$rows = $query->run();
} catch ( \Wikimedia\Rdbms\DBError $e ) {
throw $e;
} catch ( Exception $e ) {
// Allow for error handling within Lua.
throw new Scribunto_LuaError( $e->getMessage() );
Expand Down
2 changes: 2 additions & 0 deletions includes/parserfunctions/CargoQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public static function run( $parser ) {
);
$queryResultsJustForResultsTitle = $sqlQueryJustForResultsTitle->run();
}
} catch ( \Wikimedia\Rdbms\DBError $e ) {
throw $e;
} catch ( Exception $e ) {
return CargoUtils::formatError( $e->getMessage() );
}
Expand Down

0 comments on commit 3e29ed7

Please sign in to comment.