diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index bc394ffbd..d0b2c06b8 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -10,6 +10,7 @@ use Utopia\Database\Exception as DatabaseException; use Utopia\Database\Exception\Duplicate as DuplicateException; use Utopia\Database\Exception\Timeout as TimeoutException; +use Utopia\Database\Exception\Truncate as TruncateException; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; @@ -2263,7 +2264,7 @@ protected function processException(PDOException $e): \Exception // Data is too big for column resize if (($e->getCode() === '22001' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 1406) || ($e->getCode() === '01000' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 1265)) { - return new DatabaseException('Resize would result in data truncation', $e->getCode(), $e); + return new TruncateException('Resize would result in data truncation', $e->getCode(), $e); } // Duplicate index diff --git a/src/Database/Adapter/MySQL.php b/src/Database/Adapter/MySQL.php index e2b7cc81d..9ddc683c3 100644 --- a/src/Database/Adapter/MySQL.php +++ b/src/Database/Adapter/MySQL.php @@ -7,6 +7,7 @@ use Utopia\Database\Exception as DatabaseException; use Utopia\Database\Exception\Duplicate as DuplicateException; use Utopia\Database\Exception\Timeout as TimeoutException; +use Utopia\Database\Exception\Truncate as TruncateException; class MySQL extends MariaDB { @@ -108,7 +109,7 @@ protected function processException(PDOException $e): \Exception // Data is too big for column resize if (($e->getCode() === '22001' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 1406) || ($e->getCode() === '01000' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 1265)) { - return new DatabaseException('Resize would result in data truncation', $e->getCode(), $e); + return new TruncateException('Resize would result in data truncation', $e->getCode(), $e); } return $e; diff --git a/src/Database/Adapter/Postgres.php b/src/Database/Adapter/Postgres.php index 6f145b9b7..fcee00ec5 100644 --- a/src/Database/Adapter/Postgres.php +++ b/src/Database/Adapter/Postgres.php @@ -11,6 +11,7 @@ use Utopia\Database\Exception as DatabaseException; use Utopia\Database\Exception\Duplicate as DuplicateException; use Utopia\Database\Exception\Timeout as TimeoutException; +use Utopia\Database\Exception\Truncate as TruncateException; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; diff --git a/src/Database/Exception/Truncate.php b/src/Database/Exception/Truncate.php new file mode 100644 index 000000000..9bd0ffb12 --- /dev/null +++ b/src/Database/Exception/Truncate.php @@ -0,0 +1,9 @@ +updateAttribute('resize_test', 'resize_me', Database::VAR_STRING, 128, true); $this->fail('Succeeded updating attribute size to smaller size with data that is too big'); - } catch (DatabaseException $e) { - $this->assertEquals('Resize would result in data truncation', $e->getMessage()); + } catch (TruncateException $e) { } // Test going down in size when data isn't too big. @@ -5937,8 +5937,7 @@ public function testUpdateAttributeSize(): void try { static::getDatabase()->updateAttribute('resize_test', 'resize_me', Database::VAR_STRING, 128, true); $this->fail('Succeeded updating attribute size to smaller size with data that is too big'); - } catch (DatabaseException $e) { - $this->assertEquals('Resize would result in data truncation', $e->getMessage()); + } catch (TruncateException $e) { } }