Skip to content

Commit

Permalink
feat: log query for dbal exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Mar 4, 2025
1 parent 6860b5b commit b5f91fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/private/DB/ConnectionAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ 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);
}
}

public function executeUpdate(string $sql, array $params = [], array $types = []): int {
try {
return $this->inner->executeUpdate($sql, $params, $types);
} catch (Exception $e) {
throw DbalException::wrap($e);
throw DbalException::wrap($e, '', $sql);
}
}

public function executeStatement($sql, array $params = [], array $types = []): int {
try {
return $this->inner->executeStatement($sql, $params, $types);
} catch (Exception $e) {
throw DbalException::wrap($e);
throw DbalException::wrap($e, '', $sql);
}
}

Expand Down
9 changes: 6 additions & 3 deletions lib/private/DB/Exceptions/DbalException.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,29 @@
class DbalException extends Exception {
/** @var \Doctrine\DBAL\Exception */
private $original;
public ?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,
);
}

Expand Down

0 comments on commit b5f91fe

Please sign in to comment.