Skip to content

Commit 9417bcb

Browse files
committed
Update limit message
1 parent af15066 commit 9417bcb

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/Database/Database.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,7 +2712,7 @@ public function updateAttribute(string $collection, string $id, ?string $type =
27122712
$this->adapter->getDocumentSizeLimit() > 0 &&
27132713
$this->adapter->getAttributeWidth($collectionDoc) >= $this->adapter->getDocumentSizeLimit()
27142714
) {
2715-
throw new LimitException('Row width limit reached. Cannot update attribute.');
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.');
27162716
}
27172717

27182718
if (in_array($type, self::SPATIAL_TYPES, true) && !$this->adapter->getSupportForSpatialIndexNull()) {
@@ -2829,14 +2829,14 @@ public function checkAttribute(Document $collection, Document $attribute): bool
28292829
$this->adapter->getLimitForAttributes() > 0 &&
28302830
$this->adapter->getCountOfAttributes($collection) > $this->adapter->getLimitForAttributes()
28312831
) {
2832-
throw new LimitException('Column limit reached. Cannot create new attribute.');
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.');
28332833
}
28342834

28352835
if (
28362836
$this->adapter->getDocumentSizeLimit() > 0 &&
28372837
$this->adapter->getAttributeWidth($collection) >= $this->adapter->getDocumentSizeLimit()
28382838
) {
2839-
throw new LimitException('Row width limit reached. Cannot create new attribute.');
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.');
28402840
}
28412841

28422842
return true;

tests/e2e/Adapter/Scopes/AttributeTests.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -957,15 +957,17 @@ public function testExceptionAttributeLimit(): void
957957
$this->fail('Failed to throw exception');
958958
} catch (\Throwable $e) {
959959
$this->assertInstanceOf(LimitException::class, $e);
960-
$this->assertEquals('Column limit reached. Cannot create new attribute.', $e->getMessage());
960+
$this->assertStringContainsString('Column limit reached. Cannot create new attribute.', $e->getMessage());
961+
$this->assertStringContainsString('Remove some attributes to free up space.', $e->getMessage());
961962
}
962963

963964
try {
964965
$database->createAttribute($collection->getId(), 'breaking', Database::VAR_STRING, 100, true);
965966
$this->fail('Failed to throw exception');
966967
} catch (\Throwable $e) {
967968
$this->assertInstanceOf(LimitException::class, $e);
968-
$this->assertEquals('Column limit reached. Cannot create new attribute.', $e->getMessage());
969+
$this->assertStringContainsString('Column limit reached. Cannot create new attribute.', $e->getMessage());
970+
$this->assertStringContainsString('Remove some attributes to free up space.', $e->getMessage());
969971
}
970972
}
971973

@@ -1035,15 +1037,19 @@ public function testExceptionWidthLimit(): void
10351037
$this->fail('Failed to throw exception');
10361038
} catch (\Exception $e) {
10371039
$this->assertInstanceOf(LimitException::class, $e);
1038-
$this->assertEquals('Row width limit reached. Cannot create new attribute.', $e->getMessage());
1040+
$this->assertStringContainsString('Row width limit reached. Cannot create new attribute.', $e->getMessage());
1041+
$this->assertStringContainsString('bytes but the maximum is 65535 bytes', $e->getMessage());
1042+
$this->assertStringContainsString('Reduce the size of existing attributes or remove some attributes to free up space.', $e->getMessage());
10391043
}
10401044

10411045
try {
10421046
$database->createAttribute($collection->getId(), 'breaking', Database::VAR_STRING, 200, true);
10431047
$this->fail('Failed to throw exception');
10441048
} catch (\Throwable $e) {
10451049
$this->assertInstanceOf(LimitException::class, $e);
1046-
$this->assertEquals('Row width limit reached. Cannot create new attribute.', $e->getMessage());
1050+
$this->assertStringContainsString('Row width limit reached. Cannot create new attribute.', $e->getMessage());
1051+
$this->assertStringContainsString('bytes but the maximum is 65535 bytes', $e->getMessage());
1052+
$this->assertStringContainsString('Reduce the size of existing attributes or remove some attributes to free up space.', $e->getMessage());
10471053
}
10481054
}
10491055

0 commit comments

Comments
 (0)