From 3e29ed79267612dc63cf05933501ad94a31b793e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Szab=C3=B3?= Date: Tue, 5 Mar 2024 23:11:00 +0100 Subject: [PATCH] PLATFORM-9121 | Do not swallow DB errors in Cargo query 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. --- includes/CargoLuaLibrary.php | 2 ++ includes/parserfunctions/CargoQuery.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/includes/CargoLuaLibrary.php b/includes/CargoLuaLibrary.php index 2674a0fa..4df35469 100644 --- a/includes/CargoLuaLibrary.php +++ b/includes/CargoLuaLibrary.php @@ -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() ); diff --git a/includes/parserfunctions/CargoQuery.php b/includes/parserfunctions/CargoQuery.php index e267db35..a1ac2b55 100644 --- a/includes/parserfunctions/CargoQuery.php +++ b/includes/parserfunctions/CargoQuery.php @@ -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() ); }