Skip to content

Commit 7db9e96

Browse files
committed
Add size exception
1 parent 9417bcb commit 7db9e96

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/Database/Database.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Utopia\Database\Exception\Query as QueryException;
1919
use Utopia\Database\Exception\Relationship as RelationshipException;
2020
use Utopia\Database\Exception\Restricted as RestrictedException;
21+
use Utopia\Database\Exception\Size as SizeException;
2122
use Utopia\Database\Exception\Structure as StructureException;
2223
use Utopia\Database\Exception\Timeout as TimeoutException;
2324
use Utopia\Database\Exception\Type as TypeException;
@@ -2712,7 +2713,7 @@ public function updateAttribute(string $collection, string $id, ?string $type =
27122713
$this->adapter->getDocumentSizeLimit() > 0 &&
27132714
$this->adapter->getAttributeWidth($collectionDoc) >= $this->adapter->getDocumentSizeLimit()
27142715
) {
2715-
throw new LimitException('Row width limit reached. Cannot update attribute. Current row width is ' . $this->adapter->getAttributeWidth($collectionDoc) . ' bytes but the maximum is ' . $this->adapter->getDocumentSizeLimit() . ' bytes. Reduce the size of existing attributes or remove some attributes to free up space.');
2716+
throw new SizeException('Row width limit reached. Cannot update attribute. Current row width is ' . $this->adapter->getAttributeWidth($collectionDoc) . ' bytes but the maximum is ' . $this->adapter->getDocumentSizeLimit() . ' bytes. Reduce the size of existing attributes or remove some attributes to free up space.');
27162717
}
27172718

27182719
if (in_array($type, self::SPATIAL_TYPES, true) && !$this->adapter->getSupportForSpatialIndexNull()) {
@@ -2817,7 +2818,7 @@ public function updateAttribute(string $collection, string $id, ?string $type =
28172818
* @param Document $attribute
28182819
*
28192820
* @return bool
2820-
* @throws LimitException
2821+
* @throws SizeException
28212822
*/
28222823
public function checkAttribute(Document $collection, Document $attribute): bool
28232824
{
@@ -2829,14 +2830,14 @@ public function checkAttribute(Document $collection, Document $attribute): bool
28292830
$this->adapter->getLimitForAttributes() > 0 &&
28302831
$this->adapter->getCountOfAttributes($collection) > $this->adapter->getLimitForAttributes()
28312832
) {
2832-
throw new LimitException('Column limit reached. Cannot create new attribute. Current attribute count is ' . $this->adapter->getCountOfAttributes($collection) . ' but the maximum is ' . $this->adapter->getLimitForAttributes() . '. Remove some attributes to free up space.');
2833+
throw new SizeException('Column limit reached. Cannot create new attribute. Current attribute count is ' . $this->adapter->getCountOfAttributes($collection) . ' but the maximum is ' . $this->adapter->getLimitForAttributes() . '. Remove some attributes to free up space.');
28332834
}
28342835

28352836
if (
28362837
$this->adapter->getDocumentSizeLimit() > 0 &&
28372838
$this->adapter->getAttributeWidth($collection) >= $this->adapter->getDocumentSizeLimit()
28382839
) {
2839-
throw new LimitException('Row width limit reached. Cannot create new attribute. Current row width is ' . $this->adapter->getAttributeWidth($collection) . ' bytes but the maximum is ' . $this->adapter->getDocumentSizeLimit() . ' bytes. Reduce the size of existing attributes or remove some attributes to free up space.');
2840+
throw new SizeException('Row width limit reached. Cannot create new attribute. Current row width is ' . $this->adapter->getAttributeWidth($collection) . ' bytes but the maximum is ' . $this->adapter->getDocumentSizeLimit() . ' bytes. Reduce the size of existing attributes or remove some attributes to free up space.');
28402841
}
28412842

28422843
return true;

src/Database/Exception/Size.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Utopia\Database\Exception;
4+
5+
use Utopia\Database\Exception;
6+
7+
class Size extends Exception
8+
{
9+
}

tests/e2e/Adapter/Scopes/AttributeTests.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Utopia\Database\Exception\Duplicate as DuplicateException;
1515
use Utopia\Database\Exception\Limit as LimitException;
1616
use Utopia\Database\Exception\Query as QueryException;
17+
use Utopia\Database\Exception\Size as SizeException;
1718
use Utopia\Database\Exception\Structure as StructureException;
1819
use Utopia\Database\Exception\Truncate as TruncateException;
1920
use Utopia\Database\Helpers\ID;
@@ -956,7 +957,7 @@ public function testExceptionAttributeLimit(): void
956957
$database->checkAttribute($collection, $attribute);
957958
$this->fail('Failed to throw exception');
958959
} catch (\Throwable $e) {
959-
$this->assertInstanceOf(LimitException::class, $e);
960+
$this->assertInstanceOf(SizeException::class, $e);
960961
$this->assertStringContainsString('Column limit reached. Cannot create new attribute.', $e->getMessage());
961962
$this->assertStringContainsString('Remove some attributes to free up space.', $e->getMessage());
962963
}
@@ -965,7 +966,7 @@ public function testExceptionAttributeLimit(): void
965966
$database->createAttribute($collection->getId(), 'breaking', Database::VAR_STRING, 100, true);
966967
$this->fail('Failed to throw exception');
967968
} catch (\Throwable $e) {
968-
$this->assertInstanceOf(LimitException::class, $e);
969+
$this->assertInstanceOf(SizeException::class, $e);
969970
$this->assertStringContainsString('Column limit reached. Cannot create new attribute.', $e->getMessage());
970971
$this->assertStringContainsString('Remove some attributes to free up space.', $e->getMessage());
971972
}
@@ -1036,7 +1037,7 @@ public function testExceptionWidthLimit(): void
10361037
$database->checkAttribute($collection, $attribute);
10371038
$this->fail('Failed to throw exception');
10381039
} catch (\Exception $e) {
1039-
$this->assertInstanceOf(LimitException::class, $e);
1040+
$this->assertInstanceOf(SizeException::class, $e);
10401041
$this->assertStringContainsString('Row width limit reached. Cannot create new attribute.', $e->getMessage());
10411042
$this->assertStringContainsString('bytes but the maximum is 65535 bytes', $e->getMessage());
10421043
$this->assertStringContainsString('Reduce the size of existing attributes or remove some attributes to free up space.', $e->getMessage());
@@ -1046,7 +1047,7 @@ public function testExceptionWidthLimit(): void
10461047
$database->createAttribute($collection->getId(), 'breaking', Database::VAR_STRING, 200, true);
10471048
$this->fail('Failed to throw exception');
10481049
} catch (\Throwable $e) {
1049-
$this->assertInstanceOf(LimitException::class, $e);
1050+
$this->assertInstanceOf(SizeException::class, $e);
10501051
$this->assertStringContainsString('Row width limit reached. Cannot create new attribute.', $e->getMessage());
10511052
$this->assertStringContainsString('bytes but the maximum is 65535 bytes', $e->getMessage());
10521053
$this->assertStringContainsString('Reduce the size of existing attributes or remove some attributes to free up space.', $e->getMessage());

0 commit comments

Comments
 (0)