From 59e5ce0664e3bbe039e307acbc70c192610f68fe Mon Sep 17 00:00:00 2001 From: Darshan Date: Tue, 6 May 2025 16:44:19 +0530 Subject: [PATCH 1/5] update: `collections` <> `tables` errors. --- app/config/errors.php | 20 +++++++++---------- app/controllers/general.php | 2 +- src/Appwrite/Extend/Exception.php | 6 +++--- .../Modules/Databases/Http/Columns/Action.php | 6 +++--- .../Modules/Databases/Http/Columns/Delete.php | 4 ++-- .../Modules/Databases/Http/Columns/Get.php | 2 +- .../Http/Columns/Relationship/Create.php | 4 ++-- .../Modules/Databases/Http/Columns/XList.php | 2 +- .../Modules/Databases/Http/Indexes/Create.php | 2 +- .../Modules/Databases/Http/Indexes/Delete.php | 2 +- .../Modules/Databases/Http/Indexes/Get.php | 2 +- .../Modules/Databases/Http/Indexes/XList.php | 2 +- .../Modules/Databases/Http/Rows/Create.php | 4 ++-- .../Modules/Databases/Http/Rows/Delete.php | 4 ++-- .../Modules/Databases/Http/Rows/Get.php | 2 +- .../Databases/Http/Rows/Logs/XList.php | 2 +- .../Modules/Databases/Http/Rows/Update.php | 4 ++-- .../Modules/Databases/Http/Rows/XList.php | 2 +- .../Modules/Databases/Http/Tables/Create.php | 4 ++-- .../Modules/Databases/Http/Tables/Delete.php | 2 +- .../Modules/Databases/Http/Tables/Get.php | 2 +- .../Databases/Http/Tables/Logs/XList.php | 2 +- .../Modules/Databases/Http/Tables/Update.php | 2 +- .../Databases/Http/Tables/Usage/Get.php | 2 +- .../Databases/DatabasesCustomServerTest.php | 2 +- 25 files changed, 44 insertions(+), 44 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 9d30170c2d..6923090ee1 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -657,20 +657,20 @@ return [ 'code' => 400, ], - /** Collections */ - Exception::COLLECTION_NOT_FOUND => [ - 'name' => Exception::COLLECTION_NOT_FOUND, - 'description' => 'Collection with the requested ID could not be found.', + /** Tables */ + Exception::TABLE_NOT_FOUND => [ + 'name' => Exception::TABLE_NOT_FOUND, + 'description' => 'Table with the requested ID could not be found.', 'code' => 404, ], - Exception::COLLECTION_ALREADY_EXISTS => [ - 'name' => Exception::COLLECTION_ALREADY_EXISTS, - 'description' => 'A collection with the requested ID already exists. Try again with a different ID or use ID.unique() to generate a unique ID.', + Exception::TABLE_ALREADY_EXISTS => [ + 'name' => Exception::TABLE_ALREADY_EXISTS, + 'description' => 'A table with the requested ID already exists. Try again with a different ID or use ID.unique() to generate a unique ID.', 'code' => 409, ], - Exception::COLLECTION_LIMIT_EXCEEDED => [ - 'name' => Exception::COLLECTION_LIMIT_EXCEEDED, - 'description' => 'The maximum number of collections has been reached.', + Exception::TABLE_LIMIT_EXCEEDED => [ + 'name' => Exception::TABLE_LIMIT_EXCEEDED, + 'description' => 'The maximum number of tables has been reached.', 'code' => 400, ], diff --git a/app/controllers/general.php b/app/controllers/general.php index 6f46f529ce..a0e707ea2f 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -1185,7 +1185,7 @@ App::error() $error = new AppwriteException(AppwriteException::RELATIONSHIP_VALUE_INVALID, $error->getMessage(), previous: $error); break; case 'Utopia\Database\Exception\NotFound': - $error = new AppwriteException(AppwriteException::COLLECTION_NOT_FOUND, $error->getMessage(), previous: $error); + $error = new AppwriteException(AppwriteException::TABLE_NOT_FOUND, $error->getMessage(), previous: $error); break; case 'Utopia\Database\Exception\Dependency': $error = new AppwriteException(AppwriteException::INDEX_DEPENDENCY, null, previous: $error); diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 7df9134c9f..0ea0c16174 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -192,9 +192,9 @@ class Exception extends \Exception public const DATABASE_QUERY_ORDER_NULL = 'database_query_order_null'; /** Collections */ - public const COLLECTION_NOT_FOUND = 'collection_not_found'; - public const COLLECTION_ALREADY_EXISTS = 'collection_already_exists'; - public const COLLECTION_LIMIT_EXCEEDED = 'collection_limit_exceeded'; + public const TABLE_NOT_FOUND = 'table_not_found'; + public const TABLE_ALREADY_EXISTS = 'table_already_exists'; + public const TABLE_LIMIT_EXCEEDED = 'table_limit_exceeded'; /** Documents */ public const DOCUMENT_NOT_FOUND = 'document_not_found'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Action.php index 70c26594a3..109844534b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Action.php @@ -78,7 +78,7 @@ class Action extends UtopiaAction $table = $dbForProject->getDocument('database_' . $db->getInternalId(), $tableId); if ($table->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } if (!empty($format)) { @@ -100,7 +100,7 @@ class Action extends UtopiaAction $options['side'] = Database::RELATION_SIDE_PARENT; $relatedTable = $dbForProject->getDocument('database_' . $db->getInternalId(), $options['relatedCollection'] ?? ''); if ($relatedTable->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND, 'The related table was not found.'); + throw new Exception(Exception::TABLE_NOT_FOUND, 'The related table was not found.'); } } @@ -229,7 +229,7 @@ class Action extends UtopiaAction $table = $dbForProject->getDocument('database_' . $db->getInternalId(), $tableId); if ($table->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } $column = $dbForProject->getDocument('attributes', $db->getInternalId() . '_' . $table->getInternalId() . '_' . $key); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Delete.php index 945097e66b..c4c681b080 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Delete.php @@ -81,7 +81,7 @@ class Delete extends Action $table = $dbForProject->getDocument('database_' . $db->getInternalId(), $tableId); if ($table->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } $column = $dbForProject->getDocument('attributes', $db->getInternalId() . '_' . $table->getInternalId() . '_' . $key); @@ -109,7 +109,7 @@ class Delete extends Action if ($options['twoWay']) { $relatedTable = $dbForProject->getDocument('database_' . $db->getInternalId(), $options['relatedCollection']); if ($relatedTable->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } $relatedColumn = $dbForProject->getDocument('attributes', $db->getInternalId() . '_' . $relatedTable->getInternalId() . '_' . $options['twoWayKey']); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Get.php index 160ab60868..091b778eb8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Get.php @@ -75,7 +75,7 @@ class Get extends Action $table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId); if ($table->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } $column = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $table->getInternalId() . '_' . $key); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Relationship/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Relationship/Create.php index d063c8e055..9628d79a92 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Relationship/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Relationship/Create.php @@ -105,13 +105,13 @@ class Create extends ColumnAction $table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId); $table = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $table->getInternalId()); if ($table->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } $relatedTableDocument = $dbForProject->getDocument('database_' . $database->getInternalId(), $relatedTableId); $relatedTable = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $relatedTableDocument->getInternalId()); if ($relatedTable->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } $columns = $table->getAttribute('attributes', []); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/XList.php index e9800e71a0..2b212e2be3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/XList.php @@ -68,7 +68,7 @@ class XList extends Action $table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId); if ($table->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } $queries = Query::parseQueries($queries); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Create.php index 49cb7157b0..1b45f58a2f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Create.php @@ -85,7 +85,7 @@ class Create extends Action $table = $dbForProject->getDocument('database_' . $db->getInternalId(), $tableId); if ($table->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } $count = $dbForProject->count('indexes', [ diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Delete.php index eeb772e0c3..78e1799164 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Delete.php @@ -74,7 +74,7 @@ class Delete extends Action $table = $dbForProject->getDocument('database_' . $db->getInternalId(), $tableId); if ($table->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } $index = $dbForProject->getDocument('indexes', $db->getInternalId() . '_' . $table->getInternalId() . '_' . $key); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Get.php index 72ab1a02b1..b1689481ed 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Get.php @@ -67,7 +67,7 @@ class Get extends Action $table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId); if ($table->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } $index = $table->find('key', $key, 'indexes'); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/XList.php index 4920b679c1..53c623f9f4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/XList.php @@ -73,7 +73,7 @@ class XList extends Action $table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId); if ($table->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } $queries = Query::parseQueries($queries); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Create.php index 55efbc3632..adf481c1c4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Create.php @@ -106,7 +106,7 @@ class Create extends Action $table = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId)); if ($table->isEmpty() || (!$table->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } $allowedPermissions = [ @@ -246,7 +246,7 @@ class Create extends Action } catch (DuplicateException) { throw new Exception(Exception::DOCUMENT_ALREADY_EXISTS); } catch (NotFoundException) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Delete.php index bba042bca5..16e16b7d73 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Delete.php @@ -84,7 +84,7 @@ class Delete extends Action $table = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId)); if ($table->isEmpty() || (!$table->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } // Read permission should not be required for delete @@ -102,7 +102,7 @@ class Delete extends Action ); }); } catch (NotFoundException) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } // Add $tableId and $databaseId for all rows diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php index 85b6127bd3..f2da5e69f4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php @@ -79,7 +79,7 @@ class Get extends Action $table = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId)); if ($table->isEmpty() || (!$table->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Logs/XList.php index 02358be8f2..43e61c1434 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Logs/XList.php @@ -81,7 +81,7 @@ class XList extends Action $table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId); if ($table->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } $row = $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $table->getInternalId(), $rowId); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Update.php index c9ed71d569..6de7e6ae92 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Update.php @@ -101,7 +101,7 @@ class Update extends Action $table = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId)); if ($table->isEmpty() || (!$table->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } // Read permission should not be required for update @@ -243,7 +243,7 @@ class Update extends Action } catch (StructureException $e) { throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $e->getMessage()); } catch (NotFoundException) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } // Add $tableId and $databaseId for all rows diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/XList.php index 4396c2b112..95410507bf 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/XList.php @@ -79,7 +79,7 @@ class XList extends Action $table = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId)); if ($table->isEmpty() || (!$table->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Tables/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Tables/Create.php index 9acd248190..dc3f7b8574 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Tables/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Tables/Create.php @@ -99,9 +99,9 @@ class Create extends Action $dbForProject->createCollection('database_' . $database->getInternalId() . '_collection_' . $table->getInternalId(), permissions: $permissions, documentSecurity: $documentSecurity); } catch (DuplicateException) { - throw new Exception(Exception::COLLECTION_ALREADY_EXISTS); + throw new Exception(Exception::TABLE_ALREADY_EXISTS); } catch (LimitException) { - throw new Exception(Exception::COLLECTION_LIMIT_EXCEEDED); + throw new Exception(Exception::TABLE_LIMIT_EXCEEDED); } $queueForEvents diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Tables/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Tables/Delete.php index 6fe7228ed9..b7e8f6ecf7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Tables/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Tables/Delete.php @@ -71,7 +71,7 @@ class Delete extends Action $table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId); if ($table->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } if (!$dbForProject->deleteDocument('database_' . $database->getInternalId(), $tableId)) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Tables/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Tables/Get.php index 63bc1fa48c..4c76c1f89d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Tables/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Tables/Get.php @@ -66,7 +66,7 @@ class Get extends Action $table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId); if ($table->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } $response->dynamic($table, UtopiaResponse::MODEL_TABLE); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Tables/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Tables/Logs/XList.php index 44a850424f..1dba2493cf 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Tables/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Tables/Logs/XList.php @@ -81,7 +81,7 @@ class XList extends Action $table = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $tableDocument->getInternalId()); if ($table->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Tables/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Tables/Update.php index d5f8d388ab..f5621feab3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Tables/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Tables/Update.php @@ -77,7 +77,7 @@ class Update extends Action $table = $dbForProject->getDocument('database_' . $database->getInternalId(), $tableId); if ($table->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } $permissions ??= $table->getPermissions() ?? []; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Tables/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Tables/Usage/Get.php index 4c591bff1a..b528fee7cf 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Tables/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Tables/Usage/Get.php @@ -68,7 +68,7 @@ class Get extends Action $table = $dbForProject->getCollection('database_' . $database->getInternalId() . '_collection_' . $tableDocument->getInternalId()); if ($table->isEmpty()) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw new Exception(Exception::TABLE_NOT_FOUND); } $periods = Config::getParam('usage', []); diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index 508578f149..a5beb77bf3 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -3491,7 +3491,7 @@ class DatabasesCustomServerTest extends Scope ]), $payload); $this->assertEquals(404, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::COLLECTION_NOT_FOUND, $update['body']['type']); + $this->assertEquals(AppwriteException::TABLE_NOT_FOUND, $update['body']['type']); /** * Check if Attribute exists From 6e8dbfc6749bd44a53bbe4ad07dc8c27087f5554 Mon Sep 17 00:00:00 2001 From: Darshan Date: Tue, 6 May 2025 16:48:04 +0530 Subject: [PATCH 2/5] update: `documents` <> `rows` errors. --- app/config/errors.php | 44 +++++++++---------- app/controllers/general.php | 8 ++-- src/Appwrite/Extend/Exception.php | 16 +++---- .../Modules/Databases/Http/Rows/Create.php | 8 ++-- .../Modules/Databases/Http/Rows/Delete.php | 2 +- .../Modules/Databases/Http/Rows/Get.php | 2 +- .../Databases/Http/Rows/Logs/XList.php | 2 +- .../Modules/Databases/Http/Rows/Update.php | 8 ++-- .../e2e/Services/Databases/DatabasesBase.php | 2 +- .../Databases/DatabasesCustomServerTest.php | 2 +- 10 files changed, 47 insertions(+), 47 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 6923090ee1..12d494faf6 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -674,40 +674,40 @@ return [ 'code' => 400, ], - /** Documents */ - Exception::DOCUMENT_NOT_FOUND => [ - 'name' => Exception::DOCUMENT_NOT_FOUND, - 'description' => 'Document with the requested ID could not be found.', + /** Rows */ + Exception::ROW_NOT_FOUND => [ + 'name' => Exception::ROW_NOT_FOUND, + 'description' => 'Row with the requested ID could not be found.', 'code' => 404, ], - Exception::DOCUMENT_INVALID_STRUCTURE => [ - 'name' => Exception::DOCUMENT_INVALID_STRUCTURE, - 'description' => 'The document structure is invalid. Please ensure the attributes match the collection definition.', + Exception::ROW_INVALID_STRUCTURE => [ + 'name' => Exception::ROW_INVALID_STRUCTURE, + 'description' => 'The row structure is invalid. Please ensure the columns match the table definition.', 'code' => 400, ], - Exception::DOCUMENT_MISSING_DATA => [ - 'name' => Exception::DOCUMENT_MISSING_DATA, - 'description' => 'The document data is missing. Try again with document data populated', + Exception::ROW_MISSING_DATA => [ + 'name' => Exception::ROW_MISSING_DATA, + 'description' => 'The row data is missing. Try again with row data populated', 'code' => 400, ], - Exception::DOCUMENT_MISSING_PAYLOAD => [ - 'name' => Exception::DOCUMENT_MISSING_PAYLOAD, - 'description' => 'The document data and permissions are missing. You must provide either document data or permissions to be updated.', + Exception::ROW_MISSING_PAYLOAD => [ + 'name' => Exception::ROW_MISSING_PAYLOAD, + 'description' => 'The row data and permissions are missing. You must provide either row data or permissions to be updated.', 'code' => 400, ], - Exception::DOCUMENT_ALREADY_EXISTS => [ - 'name' => Exception::DOCUMENT_ALREADY_EXISTS, - 'description' => 'Document with the requested ID already exists. Try again with a different ID or use ID.unique() to generate a unique ID.', + Exception::ROW_ALREADY_EXISTS => [ + 'name' => Exception::ROW_ALREADY_EXISTS, + 'description' => 'Row with the requested ID already exists. Try again with a different ID or use ID.unique() to generate a unique ID.', 'code' => 409, ], - Exception::DOCUMENT_UPDATE_CONFLICT => [ - 'name' => Exception::DOCUMENT_UPDATE_CONFLICT, - 'description' => 'Remote document is newer than local.', + Exception::ROW_UPDATE_CONFLICT => [ + 'name' => Exception::ROW_UPDATE_CONFLICT, + 'description' => 'Remote row is newer than local.', 'code' => 409, ], - Exception::DOCUMENT_DELETE_RESTRICTED => [ - 'name' => Exception::DOCUMENT_DELETE_RESTRICTED, - 'description' => 'Document cannot be deleted because it is referenced by another document.', + Exception::ROW_DELETE_RESTRICTED => [ + 'name' => Exception::ROW_DELETE_RESTRICTED, + 'description' => 'Row cannot be deleted because it is referenced by another document.', 'code' => 403, ], diff --git a/app/controllers/general.php b/app/controllers/general.php index a0e707ea2f..cc6739e790 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -1161,7 +1161,7 @@ App::error() } break; case 'Utopia\Database\Exception\Conflict': - $error = new AppwriteException(AppwriteException::DOCUMENT_UPDATE_CONFLICT, previous: $error); + $error = new AppwriteException(AppwriteException::ROW_UPDATE_CONFLICT, previous: $error); break; case 'Utopia\Database\Exception\Timeout': $error = new AppwriteException(AppwriteException::DATABASE_TIMEOUT, previous: $error); @@ -1170,13 +1170,13 @@ App::error() $error = new AppwriteException(AppwriteException::GENERAL_QUERY_INVALID, $error->getMessage(), previous: $error); break; case 'Utopia\Database\Exception\Structure': - $error = new AppwriteException(AppwriteException::DOCUMENT_INVALID_STRUCTURE, $error->getMessage(), previous: $error); + $error = new AppwriteException(AppwriteException::ROW_INVALID_STRUCTURE, $error->getMessage(), previous: $error); break; case 'Utopia\Database\Exception\Duplicate': - $error = new AppwriteException(AppwriteException::DOCUMENT_ALREADY_EXISTS); + $error = new AppwriteException(AppwriteException::ROW_ALREADY_EXISTS); break; case 'Utopia\Database\Exception\Restricted': - $error = new AppwriteException(AppwriteException::DOCUMENT_DELETE_RESTRICTED); + $error = new AppwriteException(AppwriteException::ROW_DELETE_RESTRICTED); break; case 'Utopia\Database\Exception\Authorization': $error = new AppwriteException(AppwriteException::USER_UNAUTHORIZED); diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 0ea0c16174..6468a774ce 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -196,14 +196,14 @@ class Exception extends \Exception public const TABLE_ALREADY_EXISTS = 'table_already_exists'; public const TABLE_LIMIT_EXCEEDED = 'table_limit_exceeded'; - /** Documents */ - public const DOCUMENT_NOT_FOUND = 'document_not_found'; - public const DOCUMENT_INVALID_STRUCTURE = 'document_invalid_structure'; - public const DOCUMENT_MISSING_DATA = 'document_missing_data'; - public const DOCUMENT_MISSING_PAYLOAD = 'document_missing_payload'; - public const DOCUMENT_ALREADY_EXISTS = 'document_already_exists'; - public const DOCUMENT_UPDATE_CONFLICT = 'document_update_conflict'; - public const DOCUMENT_DELETE_RESTRICTED = 'document_delete_restricted'; + /** Rows */ + public const ROW_NOT_FOUND = 'row_not_found'; + public const ROW_INVALID_STRUCTURE = 'row_invalid_structure'; + public const ROW_MISSING_DATA = 'row_missing_data'; + public const ROW_MISSING_PAYLOAD = 'row_missing_payload'; + public const ROW_ALREADY_EXISTS = 'row_already_exists'; + public const ROW_UPDATE_CONFLICT = 'row_update_conflict'; + public const ROW_DELETE_RESTRICTED = 'row_delete_restricted'; /** Attribute */ public const ATTRIBUTE_NOT_FOUND = 'attribute_not_found'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Create.php index adf481c1c4..df36696d80 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Create.php @@ -87,11 +87,11 @@ class Create extends Action $data = (\is_string($data)) ? \json_decode($data, true) : $data; // Cast to JSON array if (empty($data)) { - throw new Exception(Exception::DOCUMENT_MISSING_DATA); + throw new Exception(Exception::ROW_MISSING_DATA); } if (isset($data['$id'])) { - throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, '$id is not allowed for creating new rows, try update instead'); + throw new Exception(Exception::ROW_INVALID_STRUCTURE, '$id is not allowed for creating new rows, try update instead'); } $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); @@ -242,9 +242,9 @@ class Create extends Action try { $row = $dbForProject->createDocument('database_' . $database->getInternalId() . '_collection_' . $table->getInternalId(), $row); } catch (StructureException $e) { - throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $e->getMessage()); + throw new Exception(Exception::ROW_INVALID_STRUCTURE, $e->getMessage()); } catch (DuplicateException) { - throw new Exception(Exception::DOCUMENT_ALREADY_EXISTS); + throw new Exception(Exception::ROW_ALREADY_EXISTS); } catch (NotFoundException) { throw new Exception(Exception::TABLE_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Delete.php index 16e16b7d73..8c68f23bfb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Delete.php @@ -91,7 +91,7 @@ class Delete extends Action $row = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $table->getInternalId(), $rowId)); if ($row->isEmpty()) { - throw new Exception(Exception::DOCUMENT_NOT_FOUND); + throw new Exception(Exception::ROW_NOT_FOUND); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php index f2da5e69f4..69127ca238 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php @@ -92,7 +92,7 @@ class Get extends Action } if ($row->isEmpty()) { - throw new Exception(Exception::DOCUMENT_NOT_FOUND); + throw new Exception(Exception::ROW_NOT_FOUND); } $operations = 0; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Logs/XList.php index 43e61c1434..238815d849 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Logs/XList.php @@ -87,7 +87,7 @@ class XList extends Action $row = $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $table->getInternalId(), $rowId); if ($row->isEmpty()) { - throw new Exception(Exception::DOCUMENT_NOT_FOUND); + throw new Exception(Exception::ROW_NOT_FOUND); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Update.php index 6de7e6ae92..7dcd1f8fcb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Update.php @@ -86,7 +86,7 @@ class Update extends Action $data = (\is_string($data)) ? \json_decode($data, true) : $data; // Cast to JSON array if (empty($data) && \is_null($permissions)) { - throw new Exception(Exception::DOCUMENT_MISSING_PAYLOAD); + throw new Exception(Exception::ROW_MISSING_PAYLOAD); } $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); @@ -109,7 +109,7 @@ class Update extends Action $row = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $table->getInternalId(), $rowId)); if ($row->isEmpty()) { - throw new Exception(Exception::DOCUMENT_NOT_FOUND); + throw new Exception(Exception::ROW_NOT_FOUND); } // Map aggregate permissions into the multiple permissions they represent. @@ -239,9 +239,9 @@ class Update extends Action } catch (AuthorizationException) { throw new Exception(Exception::USER_UNAUTHORIZED); } catch (DuplicateException) { - throw new Exception(Exception::DOCUMENT_ALREADY_EXISTS); + throw new Exception(Exception::ROW_ALREADY_EXISTS); } catch (StructureException $e) { - throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $e->getMessage()); + throw new Exception(Exception::ROW_INVALID_STRUCTURE, $e->getMessage()); } catch (NotFoundException) { throw new Exception(Exception::TABLE_NOT_FOUND); } diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 186f906252..3c2a2c4186 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -2399,7 +2399,7 @@ trait DatabasesBase $this->assertEquals(409, $response['headers']['status-code']); $this->assertEquals('Remote document is newer than local.', $response['body']['message']); - $this->assertEquals(Exception::DOCUMENT_UPDATE_CONFLICT, $response['body']['type']); + $this->assertEquals(Exception::ROW_UPDATE_CONFLICT, $response['body']['type']); return []; } diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index a5beb77bf3..314e3e1ae1 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -3417,7 +3417,7 @@ class DatabasesCustomServerTest extends Scope ); $this->assertEquals(400, $newDoc['headers']['status-code']); - $this->assertEquals(AppwriteException::DOCUMENT_INVALID_STRUCTURE, $newDoc['body']['type']); + $this->assertEquals(AppwriteException::ROW_INVALID_STRUCTURE, $newDoc['body']['type']); } /** From 7a52ace9b25c952d7d1b801ad0e76dde3f80c159 Mon Sep 17 00:00:00 2001 From: Darshan Date: Tue, 6 May 2025 16:53:20 +0530 Subject: [PATCH 3/5] update: `attributes` <> `columns` errors. --- app/config/errors.php | 66 +++++++++---------- src/Appwrite/Extend/Exception.php | 22 +++---- .../Modules/Databases/Http/Columns/Action.php | 44 ++++++------- .../Modules/Databases/Http/Columns/Delete.php | 4 +- .../Databases/Http/Columns/Enum/Create.php | 2 +- .../Databases/Http/Columns/Float/Create.php | 4 +- .../Modules/Databases/Http/Columns/Get.php | 2 +- .../Databases/Http/Columns/Integer/Create.php | 4 +- .../Http/Columns/Relationship/Create.php | 6 +- .../Databases/Http/Columns/String/Create.php | 2 +- .../Modules/Databases/Http/Indexes/Create.php | 6 +- .../Databases/DatabasesCustomServerTest.php | 38 +++++------ 12 files changed, 100 insertions(+), 100 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 12d494faf6..979bf43f7d 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -71,7 +71,7 @@ return [ ], Exception::GENERAL_QUERY_LIMIT_EXCEEDED => [ 'name' => Exception::GENERAL_QUERY_LIMIT_EXCEEDED, - 'description' => 'Query limit exceeded for the current attribute. Usage of more than 100 query values on a single attribute is prohibited.', + 'description' => 'Query limit exceeded for the current column. Usage of more than 100 query values on a single column is prohibited.', 'code' => 400, ], Exception::GENERAL_QUERY_INVALID => [ @@ -653,7 +653,7 @@ return [ ], Exception::DATABASE_QUERY_ORDER_NULL => [ 'name' => Exception::DATABASE_QUERY_ORDER_NULL, - 'description' => 'The order attribute had a null value. Cursor pagination requires all documents order attribute values are non-null.', + 'description' => 'The order column had a null value. Cursor pagination requires all rows order column values are non-null.', 'code' => 400, ], @@ -707,54 +707,54 @@ return [ ], Exception::ROW_DELETE_RESTRICTED => [ 'name' => Exception::ROW_DELETE_RESTRICTED, - 'description' => 'Row cannot be deleted because it is referenced by another document.', + 'description' => 'Row cannot be deleted because it is referenced by another row.', 'code' => 403, ], - /** Attributes */ - Exception::ATTRIBUTE_NOT_FOUND => [ - 'name' => Exception::ATTRIBUTE_NOT_FOUND, - 'description' => 'Attribute with the requested ID could not be found.', + /** Columns */ + Exception::COLUMN_NOT_FOUND => [ + 'name' => Exception::COLUMN_NOT_FOUND, + 'description' => 'Column with the requested ID could not be found.', 'code' => 404, ], - Exception::ATTRIBUTE_UNKNOWN => [ - 'name' => Exception::ATTRIBUTE_UNKNOWN, - 'description' => 'The attribute required for the index could not be found. Please confirm all your attributes are in the available state.', + Exception::COLUMN_UNKNOWN => [ + 'name' => Exception::COLUMN_UNKNOWN, + 'description' => 'The column required for the index could not be found. Please confirm all your columns are in the available state.', 'code' => 400, ], - Exception::ATTRIBUTE_NOT_AVAILABLE => [ - 'name' => Exception::ATTRIBUTE_NOT_AVAILABLE, - 'description' => 'The requested attribute is not yet available. Please try again later.', + Exception::COLUMN_NOT_AVAILABLE => [ + 'name' => Exception::COLUMN_NOT_AVAILABLE, + 'description' => 'The requested column is not yet available. Please try again later.', 'code' => 400, ], - Exception::ATTRIBUTE_FORMAT_UNSUPPORTED => [ - 'name' => Exception::ATTRIBUTE_FORMAT_UNSUPPORTED, - 'description' => 'The requested attribute format is not supported.', + Exception::COLUMN_FORMAT_UNSUPPORTED => [ + 'name' => Exception::COLUMN_FORMAT_UNSUPPORTED, + 'description' => 'The requested column format is not supported.', 'code' => 400, ], - Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED => [ - 'name' => Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED, - 'description' => 'Default values cannot be set for array or required attributes.', + Exception::COLUMN_DEFAULT_UNSUPPORTED => [ + 'name' => Exception::COLUMN_DEFAULT_UNSUPPORTED, + 'description' => 'Default values cannot be set for array or required columns.', 'code' => 400, ], - Exception::ATTRIBUTE_ALREADY_EXISTS => [ - 'name' => Exception::ATTRIBUTE_ALREADY_EXISTS, - 'description' => 'Attribute with the requested key already exists. Attribute keys must be unique, try again with a different key.', + Exception::COLUMN_ALREADY_EXISTS => [ + 'name' => Exception::COLUMN_ALREADY_EXISTS, + 'description' => 'Column with the requested key already exists. Column keys must be unique, try again with a different key.', 'code' => 409, ], - Exception::ATTRIBUTE_LIMIT_EXCEEDED => [ - 'name' => Exception::ATTRIBUTE_LIMIT_EXCEEDED, - 'description' => 'The maximum number or size of attributes for this collection has been reached.', + Exception::COLUMN_LIMIT_EXCEEDED => [ + 'name' => Exception::COLUMN_LIMIT_EXCEEDED, + 'description' => 'The maximum number or size of columns for this table has been reached.', 'code' => 400, ], - Exception::ATTRIBUTE_VALUE_INVALID => [ - 'name' => Exception::ATTRIBUTE_VALUE_INVALID, - 'description' => 'The attribute value is invalid. Please check the type, range and value of the attribute.', + Exception::COLUMN_VALUE_INVALID => [ + 'name' => Exception::COLUMN_VALUE_INVALID, + 'description' => 'The column value is invalid. Please check the type, range and value of the column.', 'code' => 400, ], - Exception::ATTRIBUTE_TYPE_INVALID => [ - 'name' => Exception::ATTRIBUTE_TYPE_INVALID, - 'description' => 'The attribute type is invalid.', + Exception::COLUMN_TYPE_INVALID => [ + 'name' => Exception::COLUMN_TYPE_INVALID, + 'description' => 'The column type is invalid.', 'code' => 400, ], Exception::RELATIONSHIP_VALUE_INVALID => [ @@ -762,8 +762,8 @@ return [ 'description' => 'The relationship value is invalid.', 'code' => 400, ], - Exception::ATTRIBUTE_INVALID_RESIZE => [ - 'name' => Exception::ATTRIBUTE_INVALID_RESIZE, + Exception::COLUMN_INVALID_RESIZE => [ + 'name' => Exception::COLUMN_INVALID_RESIZE, 'description' => "Existing data is too large for new size, truncate your existing data then try again.", 'code' => 400, ], diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 6468a774ce..31a52a6a04 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -205,17 +205,17 @@ class Exception extends \Exception public const ROW_UPDATE_CONFLICT = 'row_update_conflict'; public const ROW_DELETE_RESTRICTED = 'row_delete_restricted'; - /** Attribute */ - public const ATTRIBUTE_NOT_FOUND = 'attribute_not_found'; - public const ATTRIBUTE_UNKNOWN = 'attribute_unknown'; - public const ATTRIBUTE_NOT_AVAILABLE = 'attribute_not_available'; - public const ATTRIBUTE_FORMAT_UNSUPPORTED = 'attribute_format_unsupported'; - public const ATTRIBUTE_DEFAULT_UNSUPPORTED = 'attribute_default_unsupported'; - public const ATTRIBUTE_ALREADY_EXISTS = 'attribute_already_exists'; - public const ATTRIBUTE_LIMIT_EXCEEDED = 'attribute_limit_exceeded'; - public const ATTRIBUTE_VALUE_INVALID = 'attribute_value_invalid'; - public const ATTRIBUTE_TYPE_INVALID = 'attribute_type_invalid'; - public const ATTRIBUTE_INVALID_RESIZE = 'attribute_invalid_resize'; + /** Columns */ + public const COLUMN_NOT_FOUND = 'column_not_found'; + public const COLUMN_UNKNOWN = 'column_unknown'; + public const COLUMN_NOT_AVAILABLE = 'column_not_available'; + public const COLUMN_FORMAT_UNSUPPORTED = 'column_format_unsupported'; + public const COLUMN_DEFAULT_UNSUPPORTED = 'column_default_unsupported'; + public const COLUMN_ALREADY_EXISTS = 'column_already_exists'; + public const COLUMN_LIMIT_EXCEEDED = 'column_limit_exceeded'; + public const COLUMN_VALUE_INVALID = 'column_value_invalid'; + public const COLUMN_TYPE_INVALID = 'column_type_invalid'; + public const COLUMN_INVALID_RESIZE = 'column_invalid_resize'; /** Relationship */ public const RELATIONSHIP_VALUE_INVALID = 'relationship_value_invalid'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Action.php index 109844534b..a9415fded3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Action.php @@ -83,17 +83,17 @@ class Action extends UtopiaAction if (!empty($format)) { if (!Structure::hasFormat($format, $type)) { - throw new Exception(Exception::ATTRIBUTE_FORMAT_UNSUPPORTED, "Format {$format} not available for {$type} columns."); + throw new Exception(Exception::COLUMN_FORMAT_UNSUPPORTED, "Format {$format} not available for {$type} columns."); } } // Must throw here since dbForProject->createAttribute is performed by db worker if ($required && isset($default)) { - throw new Exception(Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED, 'Cannot set default value for required column'); + throw new Exception(Exception::COLUMN_DEFAULT_UNSUPPORTED, 'Cannot set default value for required column'); } if ($array && isset($default)) { - throw new Exception(Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED, 'Cannot set default value for array columns'); + throw new Exception(Exception::COLUMN_DEFAULT_UNSUPPORTED, 'Cannot set default value for array columns'); } if ($type === Database::VAR_RELATIONSHIP) { @@ -128,9 +128,9 @@ class Action extends UtopiaAction $dbForProject->checkAttribute($table, $column); $column = $dbForProject->createDocument('attributes', $column); } catch (DuplicateException) { - throw new Exception(Exception::ATTRIBUTE_ALREADY_EXISTS); + throw new Exception(Exception::COLUMN_ALREADY_EXISTS); } catch (LimitException) { - throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED); + throw new Exception(Exception::COLUMN_LIMIT_EXCEEDED); } catch (Throwable $e) { $dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $tableId); $dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $table->getInternalId()); @@ -171,10 +171,10 @@ class Action extends UtopiaAction $dbForProject->createDocument('attributes', $twoWayAttribute); } catch (DuplicateException) { $dbForProject->deleteDocument('attributes', $column->getId()); - throw new Exception(Exception::ATTRIBUTE_ALREADY_EXISTS); + throw new Exception(Exception::COLUMN_ALREADY_EXISTS); } catch (LimitException) { $dbForProject->deleteDocument('attributes', $column->getId()); - throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED); + throw new Exception(Exception::COLUMN_LIMIT_EXCEEDED); } catch (Throwable $e) { $dbForProject->purgeCachedDocument('database_' . $db->getInternalId(), $relatedTable->getId()); $dbForProject->purgeCachedCollection('database_' . $db->getInternalId() . '_collection_' . $relatedTable->getInternalId()); @@ -235,27 +235,27 @@ class Action extends UtopiaAction $column = $dbForProject->getDocument('attributes', $db->getInternalId() . '_' . $table->getInternalId() . '_' . $key); if ($column->isEmpty()) { - throw new Exception(Exception::ATTRIBUTE_NOT_FOUND); + throw new Exception(Exception::COLUMN_NOT_FOUND); } if ($column->getAttribute('status') !== 'available') { - throw new Exception(Exception::ATTRIBUTE_NOT_AVAILABLE); + throw new Exception(Exception::COLUMN_NOT_AVAILABLE); } if ($column->getAttribute(('type') !== $type)) { - throw new Exception(Exception::ATTRIBUTE_TYPE_INVALID); + throw new Exception(Exception::COLUMN_TYPE_INVALID); } if ($column->getAttribute('type') === Database::VAR_STRING && $column->getAttribute(('filter') !== $filter)) { - throw new Exception(Exception::ATTRIBUTE_TYPE_INVALID); + throw new Exception(Exception::COLUMN_TYPE_INVALID); } if ($required && isset($default)) { - throw new Exception(Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED, 'Cannot set default value for required column'); + throw new Exception(Exception::COLUMN_DEFAULT_UNSUPPORTED, 'Cannot set default value for required column'); } if ($column->getAttribute('array', false) && isset($default)) { - throw new Exception(Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED, 'Cannot set default value for array columns'); + throw new Exception(Exception::COLUMN_DEFAULT_UNSUPPORTED, 'Cannot set default value for array columns'); } $tableId = 'database_' . $db->getInternalId() . '_collection_' . $table->getInternalId(); @@ -275,7 +275,7 @@ class Action extends UtopiaAction $max ??= $column->getAttribute('formatOptions')['max']; if ($min > $max) { - throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, 'Minimum value must be lesser than maximum value'); + throw new Exception(Exception::COLUMN_VALUE_INVALID, 'Minimum value must be lesser than maximum value'); } if ($column->getAttribute('format') === APP_DATABASE_ATTRIBUTE_INT_RANGE) { @@ -289,7 +289,7 @@ class Action extends UtopiaAction } if (!is_null($default) && !$validator->isValid($default)) { - throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, $validator->getDescription()); + throw new Exception(Exception::COLUMN_VALUE_INVALID, $validator->getDescription()); } $options = [ @@ -301,17 +301,17 @@ class Action extends UtopiaAction break; case APP_DATABASE_ATTRIBUTE_ENUM: if (empty($elements)) { - throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, 'Enum elements must not be empty'); + throw new Exception(Exception::COLUMN_VALUE_INVALID, 'Enum elements must not be empty'); } foreach ($elements as $element) { if (\strlen($element) === 0) { - throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, 'Each enum element must not be empty'); + throw new Exception(Exception::COLUMN_VALUE_INVALID, 'Each enum element must not be empty'); } } if (!is_null($default) && !in_array($default, $elements)) { - throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, 'Default value not found in elements'); + throw new Exception(Exception::COLUMN_VALUE_INVALID, 'Default value not found in elements'); } $options = [ @@ -334,7 +334,7 @@ class Action extends UtopiaAction onDelete: $primaryRowOptions['onDelete'], ); } catch (NotFoundException) { - throw new Exception(Exception::ATTRIBUTE_NOT_FOUND); + throw new Exception(Exception::COLUMN_NOT_FOUND); } if ($primaryRowOptions['twoWay']) { @@ -364,11 +364,11 @@ class Action extends UtopiaAction newKey: $newKey ?? null ); } catch (TruncateException) { - throw new Exception(Exception::ATTRIBUTE_INVALID_RESIZE); + throw new Exception(Exception::COLUMN_INVALID_RESIZE); } catch (NotFoundException) { - throw new Exception(Exception::ATTRIBUTE_NOT_FOUND); + throw new Exception(Exception::COLUMN_NOT_FOUND); } catch (LimitException) { - throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED); + throw new Exception(Exception::COLUMN_LIMIT_EXCEEDED); } catch (IndexException $e) { throw new Exception(Exception::INDEX_INVALID, $e->getMessage()); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Delete.php index c4c681b080..717e8f958c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Delete.php @@ -86,7 +86,7 @@ class Delete extends Action $column = $dbForProject->getDocument('attributes', $db->getInternalId() . '_' . $table->getInternalId() . '_' . $key); if ($column->isEmpty()) { - throw new Exception(Exception::ATTRIBUTE_NOT_FOUND); + throw new Exception(Exception::COLUMN_NOT_FOUND); } $validator = new IndexDependencyValidator( @@ -114,7 +114,7 @@ class Delete extends Action $relatedColumn = $dbForProject->getDocument('attributes', $db->getInternalId() . '_' . $relatedTable->getInternalId() . '_' . $options['twoWayKey']); if ($relatedColumn->isEmpty()) { - throw new Exception(Exception::ATTRIBUTE_NOT_FOUND); + throw new Exception(Exception::COLUMN_NOT_FOUND); } if ($relatedColumn->getAttribute('status') === 'available') { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Enum/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Enum/Create.php index 5c5c7da071..c57d451743 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Enum/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Enum/Create.php @@ -84,7 +84,7 @@ class Create extends ColumnAction Event $queueForEvents ): void { if (!is_null($default) && !in_array($default, $elements, true)) { - throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, 'Default value not found in elements'); + throw new Exception(Exception::COLUMN_VALUE_INVALID, 'Default value not found in elements'); } $column = $this->createColumn( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Float/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Float/Create.php index 150ce8d25e..a0a16fafec 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Float/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Float/Create.php @@ -89,12 +89,12 @@ class Create extends ColumnAction $max ??= PHP_FLOAT_MAX; if ($min > $max) { - throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, 'Minimum value must be lesser than maximum value'); + throw new Exception(Exception::COLUMN_VALUE_INVALID, 'Minimum value must be lesser than maximum value'); } $validator = new Range($min, $max, Database::VAR_FLOAT); if (!\is_null($default) && !$validator->isValid($default)) { - throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, $validator->getDescription()); + throw new Exception(Exception::COLUMN_VALUE_INVALID, $validator->getDescription()); } $column = $this->createColumn($databaseId, $tableId, new Document([ diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Get.php index 091b778eb8..4390f0841c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Get.php @@ -80,7 +80,7 @@ class Get extends Action $column = $dbForProject->getDocument('attributes', $database->getInternalId() . '_' . $table->getInternalId() . '_' . $key); if ($column->isEmpty()) { - throw new Exception(Exception::ATTRIBUTE_NOT_FOUND); + throw new Exception(Exception::COLUMN_NOT_FOUND); } $type = $column->getAttribute('type'); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Integer/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Integer/Create.php index d58b79d597..cf2244bf1f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Integer/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Integer/Create.php @@ -89,12 +89,12 @@ class Create extends ColumnAction $max ??= \PHP_INT_MAX; if ($min > $max) { - throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, 'Minimum value must be lesser than maximum value'); + throw new Exception(Exception::COLUMN_VALUE_INVALID, 'Minimum value must be lesser than maximum value'); } $validator = new Range($min, $max, Database::VAR_INTEGER); if (!\is_null($default) && !$validator->isValid($default)) { - throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, $validator->getDescription()); + throw new Exception(Exception::COLUMN_VALUE_INVALID, $validator->getDescription()); } $size = $max > 2147483647 ? 8 : 4; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Relationship/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Relationship/Create.php index 9628d79a92..8b3ec616a3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/Relationship/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/Relationship/Create.php @@ -121,14 +121,14 @@ class Create extends ColumnAction } if (\strtolower($column->getId()) === \strtolower($key)) { - throw new Exception(Exception::ATTRIBUTE_ALREADY_EXISTS); + throw new Exception(Exception::COLUMN_ALREADY_EXISTS); } if ( \strtolower($column->getAttribute('options')['twoWayKey']) === \strtolower($twoWayKey) && $column->getAttribute('options')['relatedCollection'] === $relatedTable->getId() ) { - throw new Exception(Exception::ATTRIBUTE_ALREADY_EXISTS, 'Attribute with the requested key already exists. Attribute keys must be unique, try again with a different key.'); + throw new Exception(Exception::COLUMN_ALREADY_EXISTS, 'Attribute with the requested key already exists. Attribute keys must be unique, try again with a different key.'); } if ( @@ -136,7 +136,7 @@ class Create extends ColumnAction $column->getAttribute('options')['relationType'] === Database::RELATION_MANY_TO_MANY && $column->getAttribute('options')['relatedCollection'] === $relatedTable->getId() ) { - throw new Exception(Exception::ATTRIBUTE_ALREADY_EXISTS, 'Creating more than one "manyToMany" relationship on the same table is currently not permitted.'); + throw new Exception(Exception::COLUMN_ALREADY_EXISTS, 'Creating more than one "manyToMany" relationship on the same table is currently not permitted.'); } } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Columns/String/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Columns/String/Create.php index caafdbc32f..e768fda1d6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Columns/String/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Columns/String/Create.php @@ -89,7 +89,7 @@ class Create extends ColumnAction // Ensure default fits in the given size $validator = new Text($size, 0); if (!is_null($default) && !$validator->isValid($default)) { - throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, $validator->getDescription()); + throw new Exception(Exception::COLUMN_VALUE_INVALID, $validator->getDescription()); } $filters = []; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Create.php index 1b45f58a2f..537d8e27f0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Indexes/Create.php @@ -142,7 +142,7 @@ class Create extends Action $columnIndex = \array_search($column, array_column($oldColumns, 'key')); if ($columnIndex === false) { - throw new Exception(Exception::ATTRIBUTE_UNKNOWN, 'Unknown column: ' . $column . '. Verify the column name or create the column.'); + throw new Exception(Exception::COLUMN_UNKNOWN, 'Unknown column: ' . $column . '. Verify the column name or create the column.'); } $columnStatus = $oldColumns[$columnIndex]['status']; @@ -150,12 +150,12 @@ class Create extends Action $columnArray = $oldColumns[$columnIndex]['array'] ?? false; if ($columnType === Database::VAR_RELATIONSHIP) { - throw new Exception(Exception::ATTRIBUTE_TYPE_INVALID, 'Cannot create an index for a relationship column: ' . $oldColumns[$columnIndex]['key']); + throw new Exception(Exception::COLUMN_TYPE_INVALID, 'Cannot create an index for a relationship column: ' . $oldColumns[$columnIndex]['key']); } // ensure attribute is available if ($columnStatus !== 'available') { - throw new Exception(Exception::ATTRIBUTE_NOT_AVAILABLE, 'Column not available: ' . $oldColumns[$columnIndex]['key']); + throw new Exception(Exception::COLUMN_NOT_AVAILABLE, 'Column not available: ' . $oldColumns[$columnIndex]['key']); } $lengths[$i] = null; diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index 314e3e1ae1..874aa5623e 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -1785,7 +1785,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_DEFAULT_UNSUPPORTED, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_DEFAULT_UNSUPPORTED, $update['body']['type']); } /** @@ -1928,7 +1928,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_DEFAULT_UNSUPPORTED, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_DEFAULT_UNSUPPORTED, $update['body']['type']); } /** @@ -2070,7 +2070,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_DEFAULT_UNSUPPORTED, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_DEFAULT_UNSUPPORTED, $update['body']['type']); } /** @@ -2212,7 +2212,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_DEFAULT_UNSUPPORTED, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_DEFAULT_UNSUPPORTED, $update['body']['type']); } /** @@ -2430,7 +2430,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_DEFAULT_UNSUPPORTED, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_DEFAULT_UNSUPPORTED, $update['body']['type']); $update = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/integer/' . $key, array_merge([ 'content-type' => 'application/json', @@ -2444,7 +2444,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_VALUE_INVALID, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_VALUE_INVALID, $update['body']['type']); $update = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/integer/' . $key, array_merge([ 'content-type' => 'application/json', @@ -2458,7 +2458,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_VALUE_INVALID, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_VALUE_INVALID, $update['body']['type']); $update = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/integer/' . $key, array_merge([ @@ -2473,7 +2473,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_VALUE_INVALID, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_VALUE_INVALID, $update['body']['type']); } /** @@ -2691,7 +2691,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_DEFAULT_UNSUPPORTED, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_DEFAULT_UNSUPPORTED, $update['body']['type']); $update = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/float/' . $key, array_merge([ 'content-type' => 'application/json', @@ -2705,7 +2705,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_VALUE_INVALID, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_VALUE_INVALID, $update['body']['type']); $update = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/float/' . $key, array_merge([ 'content-type' => 'application/json', @@ -2719,7 +2719,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_VALUE_INVALID, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_VALUE_INVALID, $update['body']['type']); $update = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/float/' . $key, array_merge([ @@ -2734,7 +2734,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_VALUE_INVALID, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_VALUE_INVALID, $update['body']['type']); } /** @@ -2876,7 +2876,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_DEFAULT_UNSUPPORTED, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_DEFAULT_UNSUPPORTED, $update['body']['type']); } /** @@ -3018,7 +3018,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_DEFAULT_UNSUPPORTED, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_DEFAULT_UNSUPPORTED, $update['body']['type']); } /** @@ -3133,7 +3133,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_VALUE_INVALID, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_VALUE_INVALID, $update['body']['type']); $update = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/enum/' . $key, array_merge([ 'content-type' => 'application/json', @@ -3146,7 +3146,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_VALUE_INVALID, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_VALUE_INVALID, $update['body']['type']); $update = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/enum/' . $key, array_merge([ 'content-type' => 'application/json', @@ -3234,7 +3234,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_DEFAULT_UNSUPPORTED, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_DEFAULT_UNSUPPORTED, $update['body']['type']); } /** @@ -3324,7 +3324,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $attribute['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_INVALID_RESIZE, $attribute['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_INVALID_RESIZE, $attribute['body']['type']); // original documents to original size, remove new document $document = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents/' . $document['body']['$id'], array_merge([ @@ -3503,7 +3503,7 @@ class DatabasesCustomServerTest extends Scope ]), $payload); $this->assertEquals(404, $update['headers']['status-code']); - $this->assertEquals(AppwriteException::ATTRIBUTE_NOT_FOUND, $update['body']['type']); + $this->assertEquals(AppwriteException::COLUMN_NOT_FOUND, $update['body']['type']); } } From 6eb1c3ae686ad9c549522a70aef5aa587103194c Mon Sep 17 00:00:00 2001 From: Darshan Date: Tue, 6 May 2025 16:58:56 +0530 Subject: [PATCH 4/5] update: rename remaining variables. --- .../Platform/Modules/Databases/Http/Rows/Create.php | 8 ++++---- .../Platform/Modules/Databases/Http/Rows/Delete.php | 6 +++--- src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php | 2 +- .../Platform/Modules/Databases/Http/Rows/Update.php | 8 ++++---- .../Platform/Modules/Databases/Http/Rows/XList.php | 2 +- .../Platform/Modules/Databases/Workers/Databases.php | 6 +++--- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Create.php index df36696d80..87078a5d3d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Create.php @@ -175,7 +175,7 @@ class Create extends Action $relationships = \array_filter( $table->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP + fn ($column) => $column->getAttribute('type') === Database::VAR_RELATIONSHIP ); foreach ($relationships as $relationship) { @@ -257,7 +257,7 @@ class Create extends Action $relationships = \array_filter( $table->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP + fn ($column) => $column->getAttribute('type') === Database::VAR_RELATIONSHIP ); foreach ($relationships as $relationship) { @@ -296,10 +296,10 @@ class Create extends Action ->dynamic($row, UtopiaResponse::MODEL_ROW); $relationships = \array_map( - fn ($document) => $document->getAttribute('key'), + fn ($row) => $row->getAttribute('key'), \array_filter( $table->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP + fn ($column) => $column->getAttribute('type') === Database::VAR_RELATIONSHIP ) ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Delete.php index 8c68f23bfb..61cd4d218a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Delete.php @@ -112,7 +112,7 @@ class Delete extends Action $relationships = \array_filter( $table->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP + fn ($column) => $column->getAttribute('type') === Database::VAR_RELATIONSHIP ); foreach ($relationships as $relationship) { @@ -147,10 +147,10 @@ class Delete extends Action $response->addHeader('X-Debug-Operations', 1); $relationships = \array_map( - fn ($document) => $document->getAttribute('key'), + fn ($row) => $row->getAttribute('key'), \array_filter( $table->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP + fn ($column) => $column->getAttribute('type') === Database::VAR_RELATIONSHIP ) ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php index 69127ca238..fb600f5a7f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Get.php @@ -110,7 +110,7 @@ class Get extends Action $relationships = \array_filter( $table->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP + fn ($column) => $column->getAttribute('type') === Database::VAR_RELATIONSHIP ); foreach ($relationships as $relationship) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Update.php index 7dcd1f8fcb..5590aa6c67 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/Update.php @@ -156,7 +156,7 @@ class Update extends Action $relationships = \array_filter( $table->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP + fn ($column) => $column->getAttribute('type') === Database::VAR_RELATIONSHIP ); foreach ($relationships as $relationship) { @@ -253,7 +253,7 @@ class Update extends Action $relationships = \array_filter( $table->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP + fn ($column) => $column->getAttribute('type') === Database::VAR_RELATIONSHIP ); foreach ($relationships as $relationship) { @@ -284,10 +284,10 @@ class Update extends Action $response->dynamic($row, UtopiaResponse::MODEL_ROW); $relationships = \array_map( - fn ($document) => $document->getAttribute('key'), + fn ($row) => $row->getAttribute('key'), \array_filter( $table->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP + fn ($column) => $column->getAttribute('type') === Database::VAR_RELATIONSHIP ) ); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Rows/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Rows/XList.php index 95410507bf..781c0d7c83 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Rows/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Rows/XList.php @@ -136,7 +136,7 @@ class XList extends Action $relationships = \array_filter( $table->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP + fn ($column) => $column->getAttribute('type') === Database::VAR_RELATIONSHIP ); foreach ($relationships as $relationship) { diff --git a/src/Appwrite/Platform/Modules/Databases/Workers/Databases.php b/src/Appwrite/Platform/Modules/Databases/Workers/Databases.php index 6564239630..37fa7cf0cc 100644 --- a/src/Appwrite/Platform/Modules/Databases/Workers/Databases.php +++ b/src/Appwrite/Platform/Modules/Databases/Workers/Databases.php @@ -539,9 +539,9 @@ class Databases extends Action Query::contains('options', ['"relatedCollection":"'. $collectionId .'"']), ], $dbForProject, - function ($attribute) use ($dbForProject, $databaseInternalId) { - $dbForProject->purgeCachedDocument('database_' . $databaseInternalId, $attribute->getAttribute('collectionId')); - $dbForProject->purgeCachedCollection('database_' . $databaseInternalId . '_collection_' . $attribute->getAttribute('collectionInternalId')); + function ($column) use ($dbForProject, $databaseInternalId) { + $dbForProject->purgeCachedDocument('database_' . $databaseInternalId, $column->getAttribute('collectionId')); + $dbForProject->purgeCachedCollection('database_' . $databaseInternalId . '_collection_' . $column->getAttribute('collectionInternalId')); } ); From 7f023f29c56ee7123026d22e060ce2f17d222dfa Mon Sep 17 00:00:00 2001 From: Darshan Date: Wed, 7 May 2025 11:30:31 +0530 Subject: [PATCH 5/5] update: keep both tables and collections api errors. --- app/config/errors.php | 122 ++++++++++++++++++++++++++++-- app/controllers/general.php | 38 ++++++++-- src/Appwrite/Extend/Exception.php | 26 +++++++ 3 files changed, 174 insertions(+), 12 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 979bf43f7d..c1121cb98e 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -71,7 +71,7 @@ return [ ], Exception::GENERAL_QUERY_LIMIT_EXCEEDED => [ 'name' => Exception::GENERAL_QUERY_LIMIT_EXCEEDED, - 'description' => 'Query limit exceeded for the current column. Usage of more than 100 query values on a single column is prohibited.', + 'description' => 'Query limit exceeded for the current attribute/column. Usage of more than 100 query values on a single column is prohibited.', 'code' => 400, ], Exception::GENERAL_QUERY_INVALID => [ @@ -653,7 +653,24 @@ return [ ], Exception::DATABASE_QUERY_ORDER_NULL => [ 'name' => Exception::DATABASE_QUERY_ORDER_NULL, - 'description' => 'The order column had a null value. Cursor pagination requires all rows order column values are non-null.', + 'description' => 'The order attribute/column had a null value. Cursor pagination requires all documents/rows order attribute/column values are non-null.', + 'code' => 400, + ], + + /** Collections */ + Exception::COLLECTION_NOT_FOUND => [ + 'name' => Exception::COLLECTION_NOT_FOUND, + 'description' => 'Collection with the requested ID could not be found.', + 'code' => 404, + ], + Exception::COLLECTION_ALREADY_EXISTS => [ + 'name' => Exception::COLLECTION_ALREADY_EXISTS, + 'description' => 'A collection with the requested ID already exists. Try again with a different ID or use ID.unique() to generate a unique ID.', + 'code' => 409, + ], + Exception::COLLECTION_LIMIT_EXCEEDED => [ + 'name' => Exception::COLLECTION_LIMIT_EXCEEDED, + 'description' => 'The maximum number of collections has been reached.', 'code' => 400, ], @@ -674,6 +691,43 @@ return [ 'code' => 400, ], + /** Documents */ + Exception::DOCUMENT_NOT_FOUND => [ + 'name' => Exception::DOCUMENT_NOT_FOUND, + 'description' => 'Document with the requested ID could not be found.', + 'code' => 404, + ], + Exception::DOCUMENT_INVALID_STRUCTURE => [ + 'name' => Exception::DOCUMENT_INVALID_STRUCTURE, + 'description' => 'The document structure is invalid. Please ensure the attributes match the collection definition.', + 'code' => 400, + ], + Exception::DOCUMENT_MISSING_DATA => [ + 'name' => Exception::DOCUMENT_MISSING_DATA, + 'description' => 'The document data is missing. Try again with document data populated', + 'code' => 400, + ], + Exception::DOCUMENT_MISSING_PAYLOAD => [ + 'name' => Exception::DOCUMENT_MISSING_PAYLOAD, + 'description' => 'The document data and permissions are missing. You must provide either document data or permissions to be updated.', + 'code' => 400, + ], + Exception::DOCUMENT_ALREADY_EXISTS => [ + 'name' => Exception::DOCUMENT_ALREADY_EXISTS, + 'description' => 'Document with the requested ID already exists. Try again with a different ID or use ID.unique() to generate a unique ID.', + 'code' => 409, + ], + Exception::DOCUMENT_UPDATE_CONFLICT => [ + 'name' => Exception::DOCUMENT_UPDATE_CONFLICT, + 'description' => 'Remote document is newer than local.', + 'code' => 409, + ], + Exception::DOCUMENT_DELETE_RESTRICTED => [ + 'name' => Exception::DOCUMENT_DELETE_RESTRICTED, + 'description' => 'Document cannot be deleted because it is referenced by another document.', + 'code' => 403, + ], + /** Rows */ Exception::ROW_NOT_FOUND => [ 'name' => Exception::ROW_NOT_FOUND, @@ -711,6 +765,65 @@ return [ 'code' => 403, ], + /** Attributes */ + Exception::ATTRIBUTE_NOT_FOUND => [ + 'name' => Exception::ATTRIBUTE_NOT_FOUND, + 'description' => 'Attribute with the requested ID could not be found.', + 'code' => 404, + ], + Exception::ATTRIBUTE_UNKNOWN => [ + 'name' => Exception::ATTRIBUTE_UNKNOWN, + 'description' => 'The attribute required for the index could not be found. Please confirm all your attributes are in the available state.', + 'code' => 400, + ], + Exception::ATTRIBUTE_NOT_AVAILABLE => [ + 'name' => Exception::ATTRIBUTE_NOT_AVAILABLE, + 'description' => 'The requested attribute is not yet available. Please try again later.', + 'code' => 400, + ], + Exception::ATTRIBUTE_FORMAT_UNSUPPORTED => [ + 'name' => Exception::ATTRIBUTE_FORMAT_UNSUPPORTED, + 'description' => 'The requested attribute format is not supported.', + 'code' => 400, + ], + Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED => [ + 'name' => Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED, + 'description' => 'Default values cannot be set for array or required attributes.', + 'code' => 400, + ], + Exception::ATTRIBUTE_ALREADY_EXISTS => [ + 'name' => Exception::ATTRIBUTE_ALREADY_EXISTS, + 'description' => 'Attribute with the requested key already exists. Attribute keys must be unique, try again with a different key.', + 'code' => 409, + ], + Exception::ATTRIBUTE_LIMIT_EXCEEDED => [ + 'name' => Exception::ATTRIBUTE_LIMIT_EXCEEDED, + 'description' => 'The maximum number or size of attributes for this collection has been reached.', + 'code' => 400, + ], + Exception::ATTRIBUTE_VALUE_INVALID => [ + 'name' => Exception::ATTRIBUTE_VALUE_INVALID, + 'description' => 'The attribute value is invalid. Please check the type, range and value of the attribute.', + 'code' => 400, + ], + Exception::ATTRIBUTE_TYPE_INVALID => [ + 'name' => Exception::ATTRIBUTE_TYPE_INVALID, + 'description' => 'The attribute type is invalid.', + 'code' => 400, + ], + Exception::ATTRIBUTE_INVALID_RESIZE => [ + 'name' => Exception::ATTRIBUTE_INVALID_RESIZE, + 'description' => "Existing data is too large for new size, truncate your existing data then try again.", + 'code' => 400, + ], + + /** Exists for both Attributes & Columns */ + Exception::RELATIONSHIP_VALUE_INVALID => [ + 'name' => Exception::RELATIONSHIP_VALUE_INVALID, + 'description' => 'The relationship value is invalid.', + 'code' => 400, + ], + /** Columns */ Exception::COLUMN_NOT_FOUND => [ 'name' => Exception::COLUMN_NOT_FOUND, @@ -757,11 +870,6 @@ return [ 'description' => 'The column type is invalid.', 'code' => 400, ], - Exception::RELATIONSHIP_VALUE_INVALID => [ - 'name' => Exception::RELATIONSHIP_VALUE_INVALID, - 'description' => 'The relationship value is invalid.', - 'code' => 400, - ], Exception::COLUMN_INVALID_RESIZE => [ 'name' => Exception::COLUMN_INVALID_RESIZE, 'description' => "Existing data is too large for new size, truncate your existing data then try again.", diff --git a/app/controllers/general.php b/app/controllers/general.php index cc6739e790..da68d4758c 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -1148,6 +1148,9 @@ App::error() Console::error('[Error] Line: ' . $line); } + // routes like /tables, /tables/:tableId, etc. + $isTablesAPI = str_contains($route->getPath(), '/databases/:databaseId/tables'); + switch ($class) { case 'Utopia\Exception': $error = new AppwriteException(AppwriteException::GENERAL_UNKNOWN, $message, $code, $error); @@ -1161,7 +1164,12 @@ App::error() } break; case 'Utopia\Database\Exception\Conflict': - $error = new AppwriteException(AppwriteException::ROW_UPDATE_CONFLICT, previous: $error); + $error = new AppwriteException( + $isTablesAPI + ? AppwriteException::ROW_UPDATE_CONFLICT + : AppwriteException::DOCUMENT_UPDATE_CONFLICT, + previous: $error + ); break; case 'Utopia\Database\Exception\Timeout': $error = new AppwriteException(AppwriteException::DATABASE_TIMEOUT, previous: $error); @@ -1170,13 +1178,27 @@ App::error() $error = new AppwriteException(AppwriteException::GENERAL_QUERY_INVALID, $error->getMessage(), previous: $error); break; case 'Utopia\Database\Exception\Structure': - $error = new AppwriteException(AppwriteException::ROW_INVALID_STRUCTURE, $error->getMessage(), previous: $error); + $error = new AppwriteException( + $isTablesAPI + ? AppwriteException::ROW_INVALID_STRUCTURE + : AppwriteException::DOCUMENT_INVALID_STRUCTURE, + $error->getMessage(), + previous: $error + ); break; case 'Utopia\Database\Exception\Duplicate': - $error = new AppwriteException(AppwriteException::ROW_ALREADY_EXISTS); + $error = new AppwriteException( + $isTablesAPI + ? AppwriteException::ROW_ALREADY_EXISTS + : AppwriteException::DOCUMENT_ALREADY_EXISTS + ); break; case 'Utopia\Database\Exception\Restricted': - $error = new AppwriteException(AppwriteException::ROW_DELETE_RESTRICTED); + $error = new AppwriteException( + $isTablesAPI + ? AppwriteException::ROW_DELETE_RESTRICTED + : AppwriteException::DOCUMENT_DELETE_RESTRICTED + ); break; case 'Utopia\Database\Exception\Authorization': $error = new AppwriteException(AppwriteException::USER_UNAUTHORIZED); @@ -1185,7 +1207,13 @@ App::error() $error = new AppwriteException(AppwriteException::RELATIONSHIP_VALUE_INVALID, $error->getMessage(), previous: $error); break; case 'Utopia\Database\Exception\NotFound': - $error = new AppwriteException(AppwriteException::TABLE_NOT_FOUND, $error->getMessage(), previous: $error); + $error = new AppwriteException( + $isTablesAPI + ? AppwriteException::TABLE_NOT_FOUND + : AppwriteException::COLLECTION_NOT_FOUND, + $error->getMessage(), + previous: $error + ); break; case 'Utopia\Database\Exception\Dependency': $error = new AppwriteException(AppwriteException::INDEX_DEPENDENCY, null, previous: $error); diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 31a52a6a04..15b964577d 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -192,10 +192,24 @@ class Exception extends \Exception public const DATABASE_QUERY_ORDER_NULL = 'database_query_order_null'; /** Collections */ + public const COLLECTION_NOT_FOUND = 'collection_not_found'; + public const COLLECTION_ALREADY_EXISTS = 'collection_already_exists'; + public const COLLECTION_LIMIT_EXCEEDED = 'collection_limit_exceeded'; + + /** Tables */ public const TABLE_NOT_FOUND = 'table_not_found'; public const TABLE_ALREADY_EXISTS = 'table_already_exists'; public const TABLE_LIMIT_EXCEEDED = 'table_limit_exceeded'; + /** Documents */ + public const DOCUMENT_NOT_FOUND = 'document_not_found'; + public const DOCUMENT_INVALID_STRUCTURE = 'document_invalid_structure'; + public const DOCUMENT_MISSING_DATA = 'document_missing_data'; + public const DOCUMENT_MISSING_PAYLOAD = 'document_missing_payload'; + public const DOCUMENT_ALREADY_EXISTS = 'document_already_exists'; + public const DOCUMENT_UPDATE_CONFLICT = 'document_update_conflict'; + public const DOCUMENT_DELETE_RESTRICTED = 'document_delete_restricted'; + /** Rows */ public const ROW_NOT_FOUND = 'row_not_found'; public const ROW_INVALID_STRUCTURE = 'row_invalid_structure'; @@ -205,6 +219,18 @@ class Exception extends \Exception public const ROW_UPDATE_CONFLICT = 'row_update_conflict'; public const ROW_DELETE_RESTRICTED = 'row_delete_restricted'; + /** Attributes */ + public const ATTRIBUTE_NOT_FOUND = 'attribute_not_found'; + public const ATTRIBUTE_UNKNOWN = 'attribute_unknown'; + public const ATTRIBUTE_NOT_AVAILABLE = 'attribute_not_available'; + public const ATTRIBUTE_FORMAT_UNSUPPORTED = 'attribute_format_unsupported'; + public const ATTRIBUTE_DEFAULT_UNSUPPORTED = 'attribute_default_unsupported'; + public const ATTRIBUTE_ALREADY_EXISTS = 'attribute_already_exists'; + public const ATTRIBUTE_LIMIT_EXCEEDED = 'attribute_limit_exceeded'; + public const ATTRIBUTE_VALUE_INVALID = 'attribute_value_invalid'; + public const ATTRIBUTE_TYPE_INVALID = 'attribute_type_invalid'; + public const ATTRIBUTE_INVALID_RESIZE = 'attribute_invalid_resize'; + /** Columns */ public const COLUMN_NOT_FOUND = 'column_not_found'; public const COLUMN_UNKNOWN = 'column_unknown';