Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -2712,7 +2712,7 @@ public function updateAttribute(string $collection, string $id, ?string $type =
$this->adapter->getDocumentSizeLimit() > 0 &&
$this->adapter->getAttributeWidth($collectionDoc) >= $this->adapter->getDocumentSizeLimit()
) {
throw new LimitException('Row width limit reached. Cannot update attribute.');
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.');
}

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

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

return true;
Expand Down
14 changes: 10 additions & 4 deletions tests/e2e/Adapter/Scopes/AttributeTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -957,15 +957,17 @@ public function testExceptionAttributeLimit(): void
$this->fail('Failed to throw exception');
} catch (\Throwable $e) {
$this->assertInstanceOf(LimitException::class, $e);
$this->assertEquals('Column limit reached. Cannot create new attribute.', $e->getMessage());
$this->assertStringContainsString('Column limit reached. Cannot create new attribute.', $e->getMessage());
$this->assertStringContainsString('Remove some attributes to free up space.', $e->getMessage());
}

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

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

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

Expand Down