From bcb13b12958a87621f0235adfa4d71d052029027 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 26 Feb 2025 17:37:13 +0100 Subject: [PATCH] feat: log query for dbal exceptions Signed-off-by: Robin Appelman --- lib/private/DB/ConnectionAdapter.php | 6 +++--- lib/private/DB/Exceptions/DbalException.php | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/private/DB/ConnectionAdapter.php b/lib/private/DB/ConnectionAdapter.php index 2baeda9cfb7c2..3d857634a9856 100644 --- a/lib/private/DB/ConnectionAdapter.php +++ b/lib/private/DB/ConnectionAdapter.php @@ -50,7 +50,7 @@ public function executeQuery(string $sql, array $params = [], $types = []): IRes $this->inner->executeQuery($sql, $params, $types) ); } catch (Exception $e) { - throw DbalException::wrap($e); + throw DbalException::wrap($e, '', $sql); } } @@ -58,7 +58,7 @@ public function executeUpdate(string $sql, array $params = [], array $types = [] try { return $this->inner->executeUpdate($sql, $params, $types); } catch (Exception $e) { - throw DbalException::wrap($e); + throw DbalException::wrap($e, '', $sql); } } @@ -66,7 +66,7 @@ public function executeStatement($sql, array $params = [], array $types = []): i try { return $this->inner->executeStatement($sql, $params, $types); } catch (Exception $e) { - throw DbalException::wrap($e); + throw DbalException::wrap($e, '', $sql); } } diff --git a/lib/private/DB/Exceptions/DbalException.php b/lib/private/DB/Exceptions/DbalException.php index 05ea9e22a5d42..2ce6ddf80a645 100644 --- a/lib/private/DB/Exceptions/DbalException.php +++ b/lib/private/DB/Exceptions/DbalException.php @@ -35,26 +35,29 @@ class DbalException extends Exception { /** @var \Doctrine\DBAL\Exception */ private $original; + public readonly ?string $query; /** * @param \Doctrine\DBAL\Exception $original * @param int $code * @param string $message */ - private function __construct(\Doctrine\DBAL\Exception $original, int $code, string $message) { + private function __construct(\Doctrine\DBAL\Exception $original, int $code, string $message, ?string $query = null) { parent::__construct( $message, $code, $original ); $this->original = $original; + $this->query = $query; } - public static function wrap(\Doctrine\DBAL\Exception $original, string $message = ''): self { + public static function wrap(\Doctrine\DBAL\Exception $original, string $message = '', ?string $query = null): self { return new self( $original, is_int($original->getCode()) ? $original->getCode() : 0, - empty($message) ? $original->getMessage() : $message + empty($message) ? $original->getMessage() : $message, + $query, ); }