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 authored and backportbot[bot] committed Mar 4, 2025
1 parent 6860b5b commit 0fed622
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 readonly ?string $query;

Check failure

Code scanning / Psalm

ParseError Error

Syntax error, unexpected '?', expecting T_VARIABLE on line 55

Check failure on line 55 in lib/private/DB/Exceptions/DbalException.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ParseError

lib/private/DB/Exceptions/DbalException.php:55:18: ParseError: Syntax error, unexpected '?', expecting T_VARIABLE on line 55 (see https://psalm.dev/173)

/**
* @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;

Check failure

Code scanning / Psalm

UndefinedThisPropertyAssignment Error

Instance property OC\DB\Exceptions\DbalException::$query is not defined

Check failure on line 69 in lib/private/DB/Exceptions/DbalException.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedThisPropertyAssignment

lib/private/DB/Exceptions/DbalException.php:69:3: UndefinedThisPropertyAssignment: Instance property OC\DB\Exceptions\DbalException::$query is not defined (see https://psalm.dev/040)
}

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 0fed622

Please sign in to comment.