Skip to content

Commit

Permalink
feat(db): add mapping for lock wait timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
  • Loading branch information
kesselb committed May 29, 2024
1 parent b7b2966 commit 3fb0aa4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/private/DB/Exceptions/DbalException.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\Exception\InvalidFieldNameException;
use Doctrine\DBAL\Exception\LockWaitTimeoutException;
use Doctrine\DBAL\Exception\NonUniqueFieldNameException;
use Doctrine\DBAL\Exception\NotNullConstraintViolationException;
use Doctrine\DBAL\Exception\RetryableException;
Expand Down Expand Up @@ -82,6 +83,9 @@ public function getReason(): ?int {
/**
* Other server errors
*/
if ($this->original instanceof LockWaitTimeoutException) {
return parent::REASON_LOCK_WAIT_TIMEOUT;
}
if ($this->original instanceof DatabaseObjectExistsException) {
return parent::REASON_DATABASE_OBJECT_EXISTS;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/public/DB/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ class Exception extends BaseException {
*/
public const REASON_UNIQUE_CONSTRAINT_VIOLATION = 14;

/**
* The lock wait timeout was exceeded
*
* @since 30.0.0
*/
public const REASON_LOCK_WAIT_TIMEOUT = 15;

/**
* @return int|null
* @psalm-return Exception::REASON_*
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/DB/Exception/DbalExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\Exception\InvalidFieldNameException;
use Doctrine\DBAL\Exception\LockWaitTimeoutException;
use Doctrine\DBAL\Exception\NonUniqueFieldNameException;
use Doctrine\DBAL\Exception\NotNullConstraintViolationException;
use Doctrine\DBAL\Exception\ServerException;
Expand Down Expand Up @@ -45,6 +46,7 @@ public function testDriverException(string $class, int $reason): void {

public function dataDriverException(): array {
return [
[LockWaitTimeoutException::class, DbalException::REASON_LOCK_WAIT_TIMEOUT],
[ForeignKeyConstraintViolationException::class, DbalException::REASON_FOREIGN_KEY_VIOLATION],
[NotNullConstraintViolationException::class, DbalException::REASON_NOT_NULL_CONSTRAINT_VIOLATION],
[UniqueConstraintViolationException::class, DbalException::REASON_UNIQUE_CONSTRAINT_VIOLATION],
Expand Down

0 comments on commit 3fb0aa4

Please sign in to comment.