From ef5f0ed6b462be08be13fcb6e5c1c4492830df01 Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 11 Dec 2025 15:26:45 +0530 Subject: [PATCH 1/3] update: to use placeholders. --- app/config/errors.php | 74 +++++++++---------- src/Appwrite/Extend/Exception.php | 17 +++++ .../Collections/Attributes/Action.php | 28 +++---- .../Collections/Attributes/Delete.php | 12 +-- .../Databases/Collections/Attributes/Get.php | 6 +- .../Attributes/Relationship/Create.php | 10 +-- .../Collections/Attributes/XList.php | 4 +- .../Http/Databases/Collections/Create.php | 14 ++-- .../Http/Databases/Collections/Delete.php | 4 +- .../Documents/Attribute/Decrement.php | 4 +- .../Documents/Attribute/Increment.php | 4 +- .../Collections/Documents/Bulk/Delete.php | 4 +- .../Collections/Documents/Bulk/Update.php | 4 +- .../Collections/Documents/Bulk/Upsert.php | 6 +- .../Collections/Documents/Create.php | 10 +-- .../Collections/Documents/Delete.php | 8 +- .../Databases/Collections/Documents/Get.php | 6 +- .../Collections/Documents/Logs/XList.php | 6 +- .../Collections/Documents/Update.php | 10 +-- .../Collections/Documents/Upsert.php | 8 +- .../Databases/Collections/Documents/XList.php | 4 +- .../Http/Databases/Collections/Get.php | 4 +- .../Databases/Collections/Indexes/Create.php | 13 ++-- .../Databases/Collections/Indexes/Delete.php | 6 +- .../Databases/Collections/Indexes/Get.php | 6 +- .../Databases/Collections/Indexes/XList.php | 4 +- .../Http/Databases/Collections/Logs/XList.php | 4 +- .../Http/Databases/Collections/Update.php | 4 +- .../Http/Databases/Collections/Usage/Get.php | 2 +- .../Http/Databases/Collections/XList.php | 2 +- .../Databases/Http/Databases/Create.php | 8 +- .../Databases/Http/Databases/Delete.php | 2 +- .../Modules/Databases/Http/Databases/Get.php | 2 +- .../Databases/Http/Databases/Logs/XList.php | 2 +- .../Http/Databases/Transactions/Delete.php | 2 +- .../Http/Databases/Transactions/Get.php | 2 +- .../Transactions/Operations/Create.php | 8 +- .../Http/Databases/Transactions/Update.php | 9 ++- .../Databases/Http/Databases/Update.php | 2 +- .../Databases/Http/Databases/Usage/Get.php | 2 +- .../Databases/Http/TablesDB/Logs/XList.php | 2 +- .../Databases/Legacy/DatabasesBase.php | 2 +- .../Legacy/DatabasesCustomClientTest.php | 4 +- .../Legacy/DatabasesCustomServerTest.php | 2 +- .../Databases/TablesDB/DatabasesBase.php | 2 +- .../TablesDB/DatabasesCustomClientTest.php | 4 +- .../TablesDB/DatabasesCustomServerTest.php | 2 +- .../e2e/Services/GraphQL/Legacy/AuthTest.php | 3 +- .../Services/GraphQL/TablesDB/AuthTest.php | 3 +- 49 files changed, 186 insertions(+), 165 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index e9c3894f53..6d747e4eb1 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -688,12 +688,12 @@ return [ /** Databases */ Exception::DATABASE_NOT_FOUND => [ 'name' => Exception::DATABASE_NOT_FOUND, - 'description' => 'Database not found', + 'description' => 'Database with the requested ID \'%s\' could not be found.', 'code' => 404 ], Exception::DATABASE_ALREADY_EXISTS => [ 'name' => Exception::DATABASE_ALREADY_EXISTS, - 'description' => 'Database already exists', + 'description' => 'Database with the requested ID \'%s\' already exists. Try again with a different ID or use ID.unique() to generate a unique ID.', 'code' => 409 ], Exception::DATABASE_TIMEOUT => [ @@ -710,41 +710,41 @@ return [ /** Collections */ Exception::COLLECTION_NOT_FOUND => [ 'name' => Exception::COLLECTION_NOT_FOUND, - 'description' => 'Collection with the requested ID could not be found.', + 'description' => 'Collection with the requested ID \'%s\' 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.', + 'description' => 'A collection with the requested ID \'%s\' 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.', + 'description' => 'The maximum number of collections for database \'%s\' has been reached.', 'code' => 400, ], /** Tables */ Exception::TABLE_NOT_FOUND => [ 'name' => Exception::TABLE_NOT_FOUND, - 'description' => 'Table with the requested ID could not be found.', + 'description' => 'Table with the requested ID \'%s\' could not be found.', 'code' => 404, ], 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.', + 'description' => 'A table with the requested ID \'%s\' already exists. Try again with a different ID or use ID.unique() to generate a unique ID.', 'code' => 409, ], Exception::TABLE_LIMIT_EXCEEDED => [ 'name' => Exception::TABLE_LIMIT_EXCEEDED, - 'description' => 'The maximum number of tables has been reached.', + 'description' => 'The maximum number of tables for database \'%s\' has been reached.', 'code' => 400, ], /** Documents */ Exception::DOCUMENT_NOT_FOUND => [ 'name' => Exception::DOCUMENT_NOT_FOUND, - 'description' => 'Document with the requested ID could not be found.', + 'description' => 'Document with the requested ID \'%s\' could not be found.', 'code' => 404, ], Exception::DOCUMENT_INVALID_STRUCTURE => [ @@ -764,7 +764,7 @@ return [ ], 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.', + 'description' => 'Document with the requested ID \'%s\' already exists. Try again with a different ID or use ID.unique() to generate a unique ID.', 'code' => 409, ], Exception::DOCUMENT_UPDATE_CONFLICT => [ @@ -781,7 +781,7 @@ return [ /** Rows */ Exception::ROW_NOT_FOUND => [ 'name' => Exception::ROW_NOT_FOUND, - 'description' => 'Row with the requested ID could not be found.', + 'description' => 'Row with the requested ID \'%s\' could not be found.', 'code' => 404, ], Exception::ROW_INVALID_STRUCTURE => [ @@ -791,7 +791,7 @@ return [ ], Exception::ROW_MISSING_DATA => [ 'name' => Exception::ROW_MISSING_DATA, - 'description' => 'The row data is missing. Try again with row data populated', + 'description' => 'The row data is missing. Try again with row data populated.', 'code' => 400, ], Exception::ROW_MISSING_PAYLOAD => [ @@ -801,7 +801,7 @@ return [ ], 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.', + 'description' => 'Row with the requested ID \'%s\' already exists. Try again with a different ID or use ID.unique() to generate a unique ID.', 'code' => 409, ], Exception::ROW_UPDATE_CONFLICT => [ @@ -818,17 +818,17 @@ return [ /** Attributes */ Exception::ATTRIBUTE_NOT_FOUND => [ 'name' => Exception::ATTRIBUTE_NOT_FOUND, - 'description' => 'Attribute with the requested ID could not be found.', + 'description' => 'Attribute with the requested key \'%s\' 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.', + 'description' => 'The attribute \'%s\' 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.', + 'description' => 'The requested attribute \'%s\' is not yet available. Please try again later.', 'code' => 400, ], Exception::ATTRIBUTE_FORMAT_UNSUPPORTED => [ @@ -843,12 +843,12 @@ return [ ], 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.', + 'description' => 'Attribute with the requested key \'%s\' 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.', + 'description' => 'The maximum number or size of attributes for collection \'%s\' has been reached.', 'code' => 400, ], Exception::ATTRIBUTE_VALUE_INVALID => [ @@ -858,7 +858,7 @@ return [ ], Exception::ATTRIBUTE_TYPE_INVALID => [ 'name' => Exception::ATTRIBUTE_TYPE_INVALID, - 'description' => 'The attribute type is invalid.', + 'description' => 'The attribute \'%s\' type is invalid.', 'code' => 400, ], Exception::ATTRIBUTE_INVALID_RESIZE => [ @@ -869,7 +869,7 @@ return [ Exception::ATTRIBUTE_TYPE_NOT_SUPPORTED => [ 'name' => Exception::ATTRIBUTE_TYPE_NOT_SUPPORTED, - 'description' => 'Attribute type is not supported.', + 'description' => 'Attribute type \'%s\' is not supported.', 'code' => 400, ], @@ -883,17 +883,17 @@ return [ /** Columns */ Exception::COLUMN_NOT_FOUND => [ 'name' => Exception::COLUMN_NOT_FOUND, - 'description' => 'Column with the requested ID could not be found.', + 'description' => 'Column with the requested key \'%s\' could not be found.', 'code' => 404, ], 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.', + 'description' => 'The column \'%s\' required for the index could not be found. Please confirm all your columns are in the available state.', 'code' => 400, ], Exception::COLUMN_NOT_AVAILABLE => [ 'name' => Exception::COLUMN_NOT_AVAILABLE, - 'description' => 'The requested column is not yet available. Please try again later.', + 'description' => 'The requested column \'%s\' is not yet available. Please try again later.', 'code' => 400, ], Exception::COLUMN_FORMAT_UNSUPPORTED => [ @@ -908,12 +908,12 @@ return [ ], 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.', + 'description' => 'Column with the requested key \'%s\' already exists. Column keys must be unique, try again with a different key.', 'code' => 409, ], Exception::COLUMN_LIMIT_EXCEEDED => [ 'name' => Exception::COLUMN_LIMIT_EXCEEDED, - 'description' => 'The maximum number or size of columns for this table has been reached.', + 'description' => 'The maximum number or size of columns for table \'%s\' has been reached.', 'code' => 400, ], Exception::COLUMN_VALUE_INVALID => [ @@ -923,7 +923,7 @@ return [ ], Exception::COLUMN_TYPE_INVALID => [ 'name' => Exception::COLUMN_TYPE_INVALID, - 'description' => 'The column type is invalid.', + 'description' => 'The column \'%s\' type is invalid.', 'code' => 400, ], Exception::COLUMN_INVALID_RESIZE => [ @@ -933,24 +933,24 @@ return [ ], Exception::COLUMN_TYPE_NOT_SUPPORTED => [ 'name' => Exception::COLUMN_TYPE_NOT_SUPPORTED, - 'description' => 'Column type is not supported.', + 'description' => 'Column type \'%s\' is not supported.', 'code' => 400, ], /** Indexes */ Exception::INDEX_NOT_FOUND => [ 'name' => Exception::INDEX_NOT_FOUND, - 'description' => 'Index with the requested ID could not be found.', + 'description' => 'Index with the requested key \'%s\' could not be found.', 'code' => 404, ], Exception::INDEX_LIMIT_EXCEEDED => [ 'name' => Exception::INDEX_LIMIT_EXCEEDED, - 'description' => 'The maximum number of indexes has been reached.', + 'description' => 'The maximum number of indexes for collection \'%s\' has been reached.', 'code' => 400, ], Exception::INDEX_ALREADY_EXISTS => [ 'name' => Exception::INDEX_ALREADY_EXISTS, - 'description' => 'Index with the requested key already exists. Try again with a different key.', + 'description' => 'Index with the requested key \'%s\' already exists. Try again with a different key.', 'code' => 409, ], Exception::INDEX_INVALID => [ @@ -960,24 +960,24 @@ return [ ], Exception::INDEX_DEPENDENCY => [ 'name' => Exception::INDEX_DEPENDENCY, - 'description' => 'Attribute cannot be renamed or deleted. Please remove the associated index first.', + 'description' => 'Attribute \'%s\' cannot be renamed or deleted. Please remove the associated index first.', 'code' => 409, ], /** Column Indexes, same as Indexes but with different type */ Exception::COLUMN_INDEX_NOT_FOUND => [ 'name' => Exception::COLUMN_INDEX_NOT_FOUND, - 'description' => 'Index with the requested ID could not be found.', + 'description' => 'Index with the requested key \'%s\' could not be found.', 'code' => 404, ], Exception::COLUMN_INDEX_LIMIT_EXCEEDED => [ 'name' => Exception::COLUMN_INDEX_LIMIT_EXCEEDED, - 'description' => 'The maximum number of indexes has been reached.', + 'description' => 'The maximum number of indexes for table \'%s\' has been reached.', 'code' => 400, ], Exception::COLUMN_INDEX_ALREADY_EXISTS => [ 'name' => Exception::COLUMN_INDEX_ALREADY_EXISTS, - 'description' => 'Index with the requested key already exists. Try again with a different key.', + 'description' => 'Index with the requested key \'%s\' already exists. Try again with a different key.', 'code' => 409, ], Exception::COLUMN_INDEX_INVALID => [ @@ -987,19 +987,19 @@ return [ ], Exception::COLUMN_INDEX_DEPENDENCY => [ 'name' => Exception::COLUMN_INDEX_DEPENDENCY, - 'description' => 'Column cannot be renamed or deleted. Please remove the associated index first.', + 'description' => 'Column \'%s\' cannot be renamed or deleted. Please remove the associated index first.', 'code' => 409, ], /** Transactions */ Exception::TRANSACTION_NOT_FOUND => [ 'name' => Exception::TRANSACTION_NOT_FOUND, - 'description' => 'Transaction with the requested ID could not be found.', + 'description' => 'Transaction with the requested ID \'%s\' could not be found.', 'code' => 404, ], Exception::TRANSACTION_ALREADY_EXISTS => [ 'name' => Exception::TRANSACTION_ALREADY_EXISTS, - 'description' => 'Transaction with the requested ID already exists. Try again with a different ID or use ID.unique() to generate a unique ID.', + 'description' => 'Transaction with the requested ID \'%s\' already exists. Try again with a different ID or use ID.unique() to generate a unique ID.', 'code' => 409, ], Exception::TRANSACTION_INVALID => [ diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 5ecc54b86a..27d2f62059 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -412,6 +412,23 @@ class Exception extends \Exception parent::__construct($this->message, $this->code, $previous); } + /** + * Create an exception with formatted parameters. + */ + public static function withParams(string $type, mixed ...$params): self + { + $errors = Config::getParam('errors'); + $description = $errors[$type]['description'] ?? ''; + + if (!empty($params) && !empty($description)) { + $message = sprintf($description, ...$params); + } else { + $message = $description; + } + + return new self($type, $message); + } + /** * Get the type of the exception. * diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php index 48124e2a11..3156d87b7f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php @@ -307,19 +307,19 @@ abstract class Action extends UtopiaAction $options = $attribute->getAttribute('options', []); if (in_array($type, Database::SPATIAL_TYPES) && !$dbForProject->getAdapter()->getSupportForSpatialAttributes()) { - throw new Exception($this->getSpatialTypeNotSupportedException()); + throw Exception::withParams($this->getSpatialTypeNotSupportedException(), $type); } $db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($db->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } if (!empty($format)) { @@ -382,9 +382,9 @@ abstract class Action extends UtopiaAction $dbForProject->checkAttribute($collection, $attribute); $attribute = $dbForProject->createDocument('attributes', $attribute); } catch (DuplicateException) { - throw new Exception($this->getDuplicateException()); + throw Exception::withParams($this->getDuplicateException(), $key); } catch (LimitException) { - throw new Exception($this->getLimitException()); + throw Exception::withParams($this->getLimitException(), $collectionId); } catch (StructureException $e) { throw new Exception($this->getStructureException(), $e->getMessage()); } catch (Throwable $e) { @@ -426,9 +426,9 @@ abstract class Action extends UtopiaAction $dbForProject->checkAttribute($relatedCollection, $twoWayAttribute); $dbForProject->createDocument('attributes', $twoWayAttribute); } catch (DuplicateException) { - throw new Exception($this->getDuplicateException()); + throw Exception::withParams($this->getDuplicateException(), $twoWayKey); } catch (LimitException) { - throw new Exception($this->getLimitException()); + throw Exception::withParams($this->getLimitException(), $relatedCollection->getId()); } catch (StructureException) { throw new Exception($this->getStructureException()); } catch (Throwable $e) { @@ -477,19 +477,19 @@ abstract class Action extends UtopiaAction $db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($db->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } $attribute = $dbForProject->getDocument('attributes', $db->getSequence() . '_' . $collection->getSequence() . '_' . $key); if ($attribute->isEmpty()) { - throw new Exception($this->getNotFoundException()); + throw Exception::withParams($this->getNotFoundException(), $key); } if ($attribute->getAttribute('status') !== 'available') { @@ -590,7 +590,7 @@ abstract class Action extends UtopiaAction } catch (IndexException) { throw new Exception(Exception::INDEX_INVALID); } catch (LimitException) { - throw new Exception($this->getLimitException()); + throw Exception::withParams($this->getLimitException(), $collectionId); } catch (RelationshipException $e) { throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage()); } catch (StructureException $e) { @@ -624,11 +624,11 @@ abstract class Action extends UtopiaAction newKey: $newKey ?? null ); } catch (DuplicateException) { - throw new Exception($this->getDuplicateException()); + throw Exception::withParams($this->getDuplicateException(), $key); } catch (IndexException $e) { throw new Exception($this->getInvalidIndexException(), $e->getMessage()); } catch (LimitException) { - throw new Exception($this->getLimitException()); + throw Exception::withParams($this->getLimitException(), $collectionId); } catch (TruncateException) { throw new Exception($this->getInvalidResizeException()); } @@ -644,7 +644,7 @@ abstract class Action extends UtopiaAction try { $dbForProject->updateDocument('attributes', $originalUid, $attribute); } catch (DuplicateException) { - throw new Exception($this->getDuplicateException()); + throw Exception::withParams($this->getDuplicateException(), $newKey); } /** diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php index eb51044323..eff1dfe781 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php @@ -74,17 +74,17 @@ class Delete extends Action { $db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($db->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } $attribute = $dbForProject->getDocument('attributes', $db->getSequence() . '_' . $collection->getSequence() . '_' . $key); if ($attribute->isEmpty()) { - throw new Exception($this->getNotFoundException()); + throw Exception::withParams($this->getNotFoundException(), $key); } $validator = new IndexDependencyValidator( @@ -93,7 +93,7 @@ class Delete extends Action ); if (!$validator->isValid($attribute)) { - throw new Exception($this->getIndexDependencyException()); + throw Exception::withParams($this->getIndexDependencyException(), $key); } if ($attribute->getAttribute('status') === 'available') { @@ -108,12 +108,12 @@ class Delete extends Action if ($options['twoWay']) { $relatedCollection = $dbForProject->getDocument('database_' . $db->getSequence(), $options['relatedCollection']); if ($relatedCollection->isEmpty()) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $options['relatedCollection']); } $relatedAttribute = $dbForProject->getDocument('attributes', $db->getSequence() . '_' . $relatedCollection->getSequence() . '_' . $options['twoWayKey']); if ($relatedAttribute->isEmpty()) { - throw new Exception($this->getNotFoundException()); + throw Exception::withParams($this->getNotFoundException(), $options['twoWayKey']); } if ($relatedAttribute->getAttribute('status') === 'available') { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php index 91fa3582f7..f0ee593a51 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php @@ -75,17 +75,17 @@ class Get extends Action { $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } $attribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $collection->getSequence() . '_' . $key); if ($attribute->isEmpty()) { - throw new Exception($this->getNotFoundException()); + throw Exception::withParams($this->getNotFoundException(), $key); } $type = $attribute->getAttribute('type'); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php index 6fc27a9836..ecfa284c27 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php @@ -93,19 +93,19 @@ class Create extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); $collection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); if ($collection->isEmpty()) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } $relatedCollectionDocument = $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId); $relatedCollection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $relatedCollectionDocument->getSequence()); if ($relatedCollection->isEmpty()) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $relatedCollectionId); } $attributes = $collection->getAttribute('attributes', []); @@ -115,14 +115,14 @@ class Create extends Action } if (\strtolower($attribute->getId()) === \strtolower($key)) { - throw new Exception($this->getDuplicateException()); + throw Exception::withParams($this->getDuplicateException(), $key); } if ( \strtolower($attribute->getAttribute('options')['twoWayKey']) === \strtolower($twoWayKey) && $attribute->getAttribute('options')['relatedCollection'] === $relatedCollection->getId() ) { - throw new Exception($this->getDuplicateException(), 'Attribute with the requested key already exists. Attribute keys must be unique, try again with a different key.'); + throw Exception::withParams($this->getDuplicateException(), $twoWayKey); } if ( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php index c2af3ac945..2279500bca 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php @@ -71,12 +71,12 @@ class XList extends Action { $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php index f44efad298..8e23136394 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php @@ -93,7 +93,7 @@ class Create extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collectionId = $collectionId === 'unique()' ? ID::unique() : $collectionId; @@ -113,11 +113,11 @@ class Create extends Action 'search' => \implode(' ', [$collectionId, $name]), ])); } catch (DuplicateException) { - throw new Exception($this->getDuplicateException()); + throw Exception::withParams($this->getDuplicateException(), $collectionId); } catch (LimitException) { - throw new Exception($this->getLimitException()); + throw Exception::withParams($this->getLimitException(), $databaseId); } catch (NotFoundException) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collectionKey = 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(); @@ -205,13 +205,13 @@ class Create extends Action ); } catch (DuplicateException) { $dbForProject->deleteDocument($databaseKey, $collection->getId()); - throw new Exception($this->getDuplicateException()); + throw Exception::withParams($this->getDuplicateException(), $collectionId); } catch (IndexException $e) { $dbForProject->deleteDocument($databaseKey, $collection->getId()); throw new Exception($this->getInvalidIndexException(), $e->getMessage()); } catch (LimitException) { $dbForProject->deleteDocument($databaseKey, $collection->getId()); - throw new Exception($this->getLimitException()); + throw Exception::withParams($this->getLimitException(), $collectionId); } catch (\Throwable $e) { $dbForProject->deleteDocument($databaseKey, $collection->getId()); throw $e; @@ -227,7 +227,7 @@ class Create extends Action } } catch (DuplicateException) { $this->cleanup($dbForProject, $databaseKey, $collectionKey, $collection->getId()); - throw new Exception($this->getDuplicateException()); + throw Exception::withParams($this->getDuplicateException(), $collectionId); } catch (\Throwable $e) { $this->cleanup($dbForProject, $databaseKey, $collectionKey, $collection->getId()); throw $e; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php index d124a47289..a43e4dc687 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php @@ -71,12 +71,12 @@ class Delete extends Action { $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw new Exception($this->getNotFoundException()); + throw Exception::withParams($this->getNotFoundException(), $collectionId); } if (!$dbForProject->deleteDocument('database_' . $database->getSequence(), $collectionId)) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php index a5c2d1f6a8..daa3f92e7b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php @@ -95,12 +95,12 @@ class Decrement extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty()) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } // Handle transaction staging diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php index 415d3f359e..544e9f233d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php @@ -95,12 +95,12 @@ class Increment extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty()) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } // Handle transaction staging diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php index fdc4c96fe4..f9af8af9e3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php @@ -88,12 +88,12 @@ class Delete extends Action { $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } $hasRelationships = \array_filter( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php index 4adf11311e..ef065da1f8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php @@ -100,12 +100,12 @@ class Update extends Action $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } if ($transactionId === null) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php index d30135de75..b80694d4f2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php @@ -90,12 +90,12 @@ class Upsert extends Action { $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } $hasRelationships = \array_filter( @@ -180,7 +180,7 @@ class Upsert extends Action } catch (ConflictException) { throw new Exception($this->getConflictException()); } catch (DuplicateException) { - throw new Exception($this->getDuplicateException()); + throw Exception::withParams($this->getDuplicateException(), 'multiple'); } catch (RelationshipException $e) { throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage()); } catch (StructureException $e) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php index 02172d9bc3..f38df32b30 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php @@ -187,12 +187,12 @@ class Create extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } $hasRelationships = \array_filter( @@ -372,7 +372,7 @@ class Create extends Action ? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId)) : $dbForProject->getDocument('transactions', $transactionId); if ($transaction->isEmpty()) { - throw new Exception(Exception::TRANSACTION_NOT_FOUND); + throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId); } if ($transaction->getAttribute('status', '') !== 'pending') { throw new Exception(Exception::TRANSACTION_NOT_READY); @@ -444,9 +444,9 @@ class Create extends Action ) ); } catch (DuplicateException) { - throw new Exception($this->getDuplicateException()); + throw Exception::withParams($this->getDuplicateException(), $documentId); } catch (NotFoundException) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } catch (RelationshipException $e) { throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage()); } catch (StructureException $e) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php index d88e005af7..c83510ed29 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php @@ -105,13 +105,13 @@ class Delete extends Action $isPrivilegedUser = User::isPrivileged(Authorization::getRoles()); if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } // Read permission should not be required for delete @@ -125,7 +125,7 @@ class Delete extends Action } if ($document->isEmpty()) { - throw new Exception($this->getNotFoundException()); + throw Exception::withParams($this->getNotFoundException(), $documentId); } // Handle transaction staging @@ -134,7 +134,7 @@ class Delete extends Action ? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId)) : $dbForProject->getDocument('transactions', $transactionId); if ($transaction->isEmpty()) { - throw new Exception(Exception::TRANSACTION_NOT_FOUND); + throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId); } if ($transaction->getAttribute('status', '') !== 'pending') { throw new Exception(Exception::TRANSACTION_NOT_READY); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php index 5f2a966220..8e80f1ddb1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php @@ -80,13 +80,13 @@ class Get extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } try { @@ -114,7 +114,7 @@ class Get extends Action } if ($document->isEmpty()) { - throw new Exception($this->getNotFoundException()); + throw Exception::withParams($this->getNotFoundException(), $documentId); } $operations = 0; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php index 08c3cffe60..7b1447f3c3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php @@ -79,17 +79,17 @@ class XList extends Action { $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } $document = $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId); if ($document->isEmpty()) { - throw new Exception($this->getNotFoundException()); + throw Exception::withParams($this->getNotFoundException(), $documentId); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php index 428c7a45c1..165f256941 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php @@ -104,13 +104,13 @@ class Update extends Action $isPrivilegedUser = User::isPrivileged(Authorization::getRoles()); if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } if ($transactionId === null) { @@ -129,7 +129,7 @@ class Update extends Action } if ($document->isEmpty()) { - throw new Exception($this->getNotFoundException()); + throw Exception::withParams($this->getNotFoundException(), $documentId); } // Map aggregate permissions into the multiple permissions they represent. @@ -252,7 +252,7 @@ class Update extends Action ? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId)) : $dbForProject->getDocument('transactions', $transactionId); if ($transaction->isEmpty()) { - throw new Exception(Exception::TRANSACTION_NOT_FOUND); + throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId); } if ($transaction->getAttribute('status', '') !== 'pending') { throw new Exception(Exception::TRANSACTION_NOT_READY); @@ -326,7 +326,7 @@ class Update extends Action } catch (ConflictException) { throw new Exception($this->getConflictException()); } catch (DuplicateException) { - throw new Exception($this->getDuplicateException()); + throw Exception::withParams($this->getDuplicateException(), $documentId); } catch (RelationshipException $e) { throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage()); } catch (StructureException $e) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php index 76b1099f6b..7ff78bf913 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php @@ -111,12 +111,12 @@ class Upsert extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } if ($transactionId === null) { @@ -262,7 +262,7 @@ class Upsert extends Action ? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId)) : $dbForProject->getDocument('transactions', $transactionId); if ($transaction->isEmpty()) { - throw new Exception(Exception::TRANSACTION_NOT_FOUND); + throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId); } if ($transaction->getAttribute('status', '') !== 'pending') { throw new Exception(Exception::TRANSACTION_NOT_READY); @@ -335,7 +335,7 @@ class Upsert extends Action } catch (ConflictException) { throw new Exception($this->getConflictException()); } catch (DuplicateException) { - throw new Exception($this->getDuplicateException()); + throw Exception::withParams($this->getDuplicateException(), $documentId); } catch (RelationshipException $e) { throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage()); } catch (StructureException $e) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php index 8bbaecedc9..43f56d694e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php @@ -84,12 +84,12 @@ class XList extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception($this->getParentNotFoundException()); + throw Exception::withParams($this->getParentNotFoundException(), $collectionId); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php index 89739570c7..1ff71110bf 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php @@ -65,13 +65,13 @@ class Get extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw new Exception($this->getNotFoundException()); + throw Exception::withParams($this->getNotFoundException(), $collectionId); } $response->dynamic($collection, $this->getResponseModel()); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php index 812bae16e2..0f1b473bea 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php @@ -87,14 +87,14 @@ class Create extends Action $db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($db->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId); if ($collection->isEmpty()) { // table or collection. - throw new Exception($this->getGrandParentNotFoundException()); + throw Exception::withParams($this->getGrandParentNotFoundException(), $collectionId); } $count = $dbForProject->count('indexes', [ @@ -105,7 +105,7 @@ class Create extends Action $limit = $dbForProject->getLimitForIndexes(); if ($count >= $limit) { - throw new Exception($this->getLimitException(), 'Index limit exceeded'); + throw Exception::withParams($this->getLimitException(), $collectionId); } $oldAttributes = \array_map( @@ -148,7 +148,7 @@ class Create extends Action $attributeIndex = \array_search($attribute, array_column($oldAttributes, 'key')); if ($attributeIndex === false) { - throw new Exception($this->getParentUnknownException(), "Unknown $contextType: " . $attribute . ". Verify the $contextType name or create the $contextType."); + throw Exception::withParams($this->getParentUnknownException(), $attribute); } $attributeStatus = $oldAttributes[$attributeIndex]['status']; @@ -160,8 +160,7 @@ class Create extends Action } if ($attributeStatus !== 'available') { - $contextType = ucfirst($contextType); - throw new Exception($this->getParentNotAvailableException(), "$contextType not available: " . $oldAttributes[$attributeIndex]['key']); + throw Exception::withParams($this->getParentNotAvailableException(), $oldAttributes[$attributeIndex]['key']); } if (empty($lengths[$i])) { @@ -209,7 +208,7 @@ class Create extends Action try { $index = $dbForProject->createDocument('indexes', $index); } catch (DuplicateException) { - throw new Exception($this->getDuplicateException()); + throw Exception::withParams($this->getDuplicateException(), $key); } $dbForProject->purgeCachedDocument('database_' . $db->getSequence(), $collectionId); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php index 2bccfdfb52..b9caeb3720 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php @@ -78,19 +78,19 @@ class Delete extends Action $db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($db->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId); if ($collection->isEmpty()) { // table or collection. - throw new Exception($this->getGrandParentNotFoundException()); + throw Exception::withParams($this->getGrandParentNotFoundException(), $collectionId); } $index = $dbForProject->getDocument('indexes', $db->getSequence() . '_' . $collection->getSequence() . '_' . $key); if (empty($index->getId())) { - throw new Exception($this->getNotFoundException()); + throw Exception::withParams($this->getNotFoundException(), $key); } // Only update status if removing available index diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php index 3d118d1922..c16ac12a91 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php @@ -67,18 +67,18 @@ class Get extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { // table or collection. - throw new Exception($this->getGrandParentNotFoundException()); + throw Exception::withParams($this->getGrandParentNotFoundException(), $collectionId); } $index = $collection->find('key', $key, 'indexes'); if (empty($index)) { - throw new Exception($this->getNotFoundException()); + throw Exception::withParams($this->getNotFoundException(), $key); } $response->dynamic($index, $this->getResponseModel()); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php index 88b3a32e0b..38213ee4c1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php @@ -75,14 +75,14 @@ class XList extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { // table or collection. - throw new Exception($this->getGrandParentNotFoundException()); + throw Exception::withParams($this->getGrandParentNotFoundException(), $collectionId); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php index 6662c56720..7d0b1ab67f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php @@ -79,14 +79,14 @@ class XList extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collectionDocument = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); $collection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $collectionDocument->getSequence()); if ($collection->isEmpty()) { - throw new Exception($this->getNotFoundException()); + throw Exception::withParams($this->getNotFoundException(), $collectionId); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php index 7575c9803b..f1b78bf7c2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php @@ -78,12 +78,12 @@ class Update extends Action { $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw new Exception($this->getNotFoundException()); + throw Exception::withParams($this->getNotFoundException(), $collectionId); } $permissions ??= $collection->getPermissions(); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php index 9cf7b85267..d270bc5efc 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php @@ -73,7 +73,7 @@ class Get extends Action $collection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $collectionDocument->getSequence()); if ($collection->isEmpty()) { - throw new Exception($this->getNotFoundException()); + throw Exception::withParams($this->getNotFoundException(), $collectionId); } $periods = Config::getParam('usage', []); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php index 286e48420a..9430394a19 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php @@ -75,7 +75,7 @@ class XList extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php index 110ec99a9d..7c8d75a2d1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php @@ -84,7 +84,7 @@ class Create extends Action 'type' => $this->getDatabaseType(), ])); } catch (DuplicateException) { - throw new Exception(Exception::DATABASE_ALREADY_EXISTS); + throw Exception::withParams(Exception::DATABASE_ALREADY_EXISTS, $databaseId); } catch (StructureException $e) { throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $e->getMessage()); } @@ -109,13 +109,13 @@ class Create extends Action try { $dbForProject->createCollection('database_' . $database->getSequence(), $attributes, $indexes); } catch (DuplicateException) { - throw new Exception(Exception::DATABASE_ALREADY_EXISTS); - } catch (IndexException) { + throw Exception::withParams(Exception::DATABASE_ALREADY_EXISTS, $databaseId); + } catch (IndexException $e) { throw new Exception(Exception::INDEX_INVALID); } catch (LimitException) { // TODO: @Jake, how do we handle this collection/table? // there's no context awareness at this level on what the api is. - throw new Exception(Exception::COLLECTION_LIMIT_EXCEEDED); + throw Exception::withParams(Exception::COLLECTION_LIMIT_EXCEEDED, $databaseId); } $queueForEvents->setParam('databaseId', $database->getId()); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php index 7be96fa883..c181b9ac45 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php @@ -69,7 +69,7 @@ class Delete extends Action $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } if (!$dbForProject->deleteDocument('databases', $databaseId)) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php index c4626c804c..33c11efbda 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php @@ -61,7 +61,7 @@ class Get extends Action $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $response->dynamic($database, UtopiaResponse::MODEL_DATABASE); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php index 3653d423b6..0a496f9b9e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php @@ -75,7 +75,7 @@ class XList extends Action $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Delete.php index a5d2562572..d799ccc200 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Delete.php @@ -60,7 +60,7 @@ class Delete extends Action $transaction = $dbForProject->getDocument('transactions', $transactionId); if ($transaction->isEmpty()) { - throw new Exception(Exception::TRANSACTION_NOT_FOUND); + throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId); } $dbForProject->deleteDocument('transactions', $transactionId); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php index 1d4d22baa1..3b153fd0a4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php @@ -58,7 +58,7 @@ class Get extends Action $transaction = $dbForProject->getDocument('transactions', $transactionId); if ($transaction->isEmpty()) { - throw new Exception(Exception::TRANSACTION_NOT_FOUND); + throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId); } $response diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php index 61da52e830..545031698f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php @@ -80,7 +80,7 @@ class Create extends Action ? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId)) : $dbForProject->getDocument('transactions', $transactionId); if ($transaction->isEmpty()) { - throw new Exception(Exception::TRANSACTION_NOT_FOUND); + throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId); } if ($transaction->getAttribute('status', '') !== 'pending') { throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Invalid or non‑pending transaction'); @@ -115,14 +115,14 @@ class Create extends Action $database = $databases[$operation['databaseId']] ??= Authorization::skip(fn () => $dbForProject->getDocument('databases', $operation['databaseId'])); if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $operation['databaseId']); } $collection = $collections[$operation[$this->getGroupId()]] ??= Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $operation[$this->getGroupId()])); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw new Exception(Exception::COLLECTION_NOT_FOUND); + throw Exception::withParams(Exception::COLLECTION_NOT_FOUND, $operation[$this->getGroupId()]); } if (\in_array($operation['action'], ['bulkCreate', 'bulkUpdate', 'bulkUpsert', 'bulkDelete'])) { @@ -148,7 +148,7 @@ class Create extends Action $document = $transactionState->getDocument($collectionKey, $documentId, $transactionId); if ($document->isEmpty() && !$isDependant && $operation['action'] !== 'upsert') { - throw new Exception(Exception::DOCUMENT_NOT_FOUND); + throw Exception::withParams(Exception::DOCUMENT_NOT_FOUND, $documentId); } } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php index aec72a029a..df9b6f895a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php @@ -118,7 +118,7 @@ class Update extends Action ? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId)) : $dbForProject->getDocument('transactions', $transactionId); if ($transaction->isEmpty()) { - throw new Exception(Exception::TRANSACTION_NOT_FOUND); + throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId); } if ($transaction->getAttribute('status', '') !== 'pending') { throw new Exception(Exception::TRANSACTION_NOT_READY); @@ -135,9 +135,10 @@ class Update extends Action $operations = []; $totalOperations = 0; $databaseOperations = []; + $currentDocumentId = null; try { - $dbForProject->withTransaction(function () use ($dbForProject, $transactionState, $queueForDeletes, $transactionId, &$transaction, &$operations, &$totalOperations, &$databaseOperations, $queueForEvents, $queueForStatsUsage, $queueForRealtime, $queueForFunctions, $queueForWebhooks) { + $dbForProject->withTransaction(function () use ($dbForProject, $transactionState, $queueForDeletes, $transactionId, &$transaction, &$operations, &$totalOperations, &$databaseOperations, &$currentDocumentId, $queueForEvents, $queueForStatsUsage, $queueForRealtime, $queueForFunctions, $queueForWebhooks) { Authorization::skip(fn () => $dbForProject->updateDocument('transactions', $transactionId, new Document([ 'status' => 'committing', ]))); @@ -156,6 +157,7 @@ class Update extends Action $collectionInternalId = $operation['collectionInternalId']; $collectionId = "database_{$databaseInternalId}_collection_{$collectionInternalId}"; $documentId = $operation['documentId']; + $currentDocumentId = $documentId; $createdAt = new \DateTime($operation['$createdAt']); $action = $operation['action']; $data = $operation['data']; @@ -244,7 +246,8 @@ class Update extends Action Authorization::skip(fn () => $dbForProject->updateDocument('transactions', $transactionId, new Document([ 'status' => 'failed', ]))); - throw new Exception(Exception::DOCUMENT_NOT_FOUND, previous: $e); + + throw Exception::withParams(Exception::DOCUMENT_NOT_FOUND, $currentDocumentId ?? 'unknown', previous: $e); } catch (DuplicateException | ConflictException $e) { Authorization::skip(fn () => $dbForProject->updateDocument('transactions', $transactionId, new Document([ 'status' => 'failed', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php index d3057c1ca5..4030040ee3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php @@ -70,7 +70,7 @@ class Update extends Action $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $database = $dbForProject->updateDocument('databases', $databaseId, $database diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php index c9de9d5217..ce0d1ad16d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php @@ -67,7 +67,7 @@ class Get extends Action $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } $periods = Config::getParam('usage', []); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php index ac24e1d882..ce1bc35e75 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php @@ -70,7 +70,7 @@ class XList extends Action $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw new Exception(Exception::DATABASE_NOT_FOUND); + throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); } try { diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php index 12981ff262..d43d183e5a 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesBase.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php @@ -1392,7 +1392,7 @@ trait DatabasesBase ]); $this->assertEquals(400, $unknown['headers']['status-code']); - $this->assertEquals('Unknown attribute: Unknown. Verify the attribute name or create the attribute.', $unknown['body']['message']); + $this->assertEquals('The attribute \'Unknown\' required for the index could not be found. Please confirm all your attributes are in the available state.', $unknown['body']['message']); $index1 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/indexes', array_merge([ 'content-type' => 'application/json', diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesCustomClientTest.php b/tests/e2e/Services/Databases/Legacy/DatabasesCustomClientTest.php index 699a2b8f25..0fe5d21da1 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesCustomClientTest.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesCustomClientTest.php @@ -398,7 +398,7 @@ class DatabasesCustomClientTest extends Scope \sleep(2); $this->assertEquals(409, $relation['body']['code']); - $this->assertEquals('Attribute with the requested key already exists. Attribute keys must be unique, try again with a different key.', $relation['body']['message']); + $this->assertEquals('Attribute with the requested key \'same_key\' already exists. Attribute keys must be unique, try again with a different key.', $relation['body']['message']); // twoWayKey is null TwoWayKey is default $relation = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection1['body']['$id'] . '/attributes/relationship', array_merge([ @@ -433,7 +433,7 @@ class DatabasesCustomClientTest extends Scope \sleep(2); - $this->assertEquals('Attribute with the requested key already exists. Attribute keys must be unique, try again with a different key.', $relation['body']['message']); + $this->assertEquals('Attribute with the requested key \'attr4\' already exists. Attribute keys must be unique, try again with a different key.', $relation['body']['message']); $this->assertEquals(409, $relation['body']['code']); // RelationshipManyToMany diff --git a/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php index ef7091d771..7e960d82d5 100644 --- a/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesCustomServerTest.php @@ -1567,7 +1567,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $tooMany['headers']['status-code']); - $this->assertEquals('Index limit exceeded', $tooMany['body']['message']); + $this->assertEquals("The maximum number of indexes for collection '$collectionId' has been reached.", $tooMany['body']['message']); $collection = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ 'content-type' => 'application/json', diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php index f2df01ebb0..e74431c779 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php @@ -1374,7 +1374,7 @@ trait DatabasesBase ]); $this->assertEquals(400, $unknown['headers']['status-code']); - $this->assertEquals('Unknown column: Unknown. Verify the column name or create the column.', $unknown['body']['message']); + $this->assertEquals('The column \'Unknown\' required for the index could not be found. Please confirm all your columns are in the available state.', $unknown['body']['message']); $index1 = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $data['moviesId'] . '/indexes', array_merge([ 'content-type' => 'application/json', diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesCustomClientTest.php b/tests/e2e/Services/Databases/TablesDB/DatabasesCustomClientTest.php index f986b5dd03..dc7c3a47b6 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesCustomClientTest.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesCustomClientTest.php @@ -398,7 +398,7 @@ class DatabasesCustomClientTest extends Scope \sleep(2); $this->assertEquals(409, $relation['body']['code']); - $this->assertEquals('Attribute with the requested key already exists. Attribute keys must be unique, try again with a different key.', $relation['body']['message']); + $this->assertEquals('Column with the requested key \'same_key\' already exists. Column keys must be unique, try again with a different key.', $relation['body']['message']); // twoWayKey is null TwoWayKey is default $relation = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $table1['body']['$id'] . '/columns/relationship', array_merge([ @@ -433,7 +433,7 @@ class DatabasesCustomClientTest extends Scope \sleep(2); - $this->assertEquals('Attribute with the requested key already exists. Attribute keys must be unique, try again with a different key.', $relation['body']['message']); + $this->assertEquals('Column with the requested key \'attr4\' already exists. Column keys must be unique, try again with a different key.', $relation['body']['message']); $this->assertEquals(409, $relation['body']['code']); // RelationshipManyToMany diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php index 7b84420640..b0b80ce3b6 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesCustomServerTest.php @@ -1496,7 +1496,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $tooMany['headers']['status-code']); - $this->assertEquals('Index limit exceeded', $tooMany['body']['message']); + $this->assertEquals("The maximum number of indexes for table '$tableId' has been reached.", $tooMany['body']['message']); $table = $this->client->call(Client::METHOD_DELETE, '/tablesdb/' . $databaseId . '/tables/' . $tableId, array_merge([ 'content-type' => 'application/json', diff --git a/tests/e2e/Services/GraphQL/Legacy/AuthTest.php b/tests/e2e/Services/GraphQL/Legacy/AuthTest.php index 560f0693ea..7c1086b075 100644 --- a/tests/e2e/Services/GraphQL/Legacy/AuthTest.php +++ b/tests/e2e/Services/GraphQL/Legacy/AuthTest.php @@ -199,7 +199,8 @@ class AuthTest extends Scope ], $gqlPayload); $this->assertArrayHasKey('errors', $document['body']); - $this->assertEquals('Document with the requested ID could not be found.', $document['body']['errors'][0]['message']); + $documentId = $gqlPayload['variables']['documentId']; + $this->assertEquals("Document with the requested ID '$documentId' could not be found.", $document['body']['errors'][0]['message']); } public function testValidAuth() diff --git a/tests/e2e/Services/GraphQL/TablesDB/AuthTest.php b/tests/e2e/Services/GraphQL/TablesDB/AuthTest.php index 5b5e721323..ded79a4a71 100644 --- a/tests/e2e/Services/GraphQL/TablesDB/AuthTest.php +++ b/tests/e2e/Services/GraphQL/TablesDB/AuthTest.php @@ -199,7 +199,8 @@ class AuthTest extends Scope ], $gqlPayload); $this->assertArrayHasKey('errors', $row['body']); - $this->assertEquals('Row with the requested ID could not be found.', $row['body']['errors'][0]['message']); + $rowId = $gqlPayload['variables']['rowId']; + $this->assertEquals("Row with the requested ID '$rowId' could not be found.", $row['body']['errors'][0]['message']); } public function testValidAuth() From cb9705f0a2da9328f0a09eab20a1065d028c6036 Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 11 Dec 2025 15:59:24 +0530 Subject: [PATCH 2/3] update: better signature. --- src/Appwrite/Extend/Exception.php | 28 ++++++------------- .../Collections/Attributes/Action.php | 28 +++++++++---------- .../Collections/Attributes/Delete.php | 12 ++++---- .../Databases/Collections/Attributes/Get.php | 6 ++-- .../Attributes/Relationship/Create.php | 10 +++---- .../Collections/Attributes/XList.php | 4 +-- .../Http/Databases/Collections/Create.php | 14 +++++----- .../Http/Databases/Collections/Delete.php | 4 +-- .../Documents/Attribute/Decrement.php | 4 +-- .../Documents/Attribute/Increment.php | 4 +-- .../Collections/Documents/Bulk/Delete.php | 4 +-- .../Collections/Documents/Bulk/Update.php | 4 +-- .../Collections/Documents/Bulk/Upsert.php | 6 ++-- .../Collections/Documents/Create.php | 10 +++---- .../Collections/Documents/Delete.php | 8 +++--- .../Databases/Collections/Documents/Get.php | 6 ++-- .../Collections/Documents/Logs/XList.php | 6 ++-- .../Collections/Documents/Update.php | 10 +++---- .../Collections/Documents/Upsert.php | 8 +++--- .../Databases/Collections/Documents/XList.php | 4 +-- .../Http/Databases/Collections/Get.php | 4 +-- .../Databases/Collections/Indexes/Create.php | 12 ++++---- .../Databases/Collections/Indexes/Delete.php | 6 ++-- .../Databases/Collections/Indexes/Get.php | 6 ++-- .../Databases/Collections/Indexes/XList.php | 4 +-- .../Http/Databases/Collections/Logs/XList.php | 4 +-- .../Http/Databases/Collections/Update.php | 4 +-- .../Http/Databases/Collections/Usage/Get.php | 2 +- .../Http/Databases/Collections/XList.php | 2 +- .../Databases/Http/Databases/Create.php | 6 ++-- .../Databases/Http/Databases/Delete.php | 2 +- .../Modules/Databases/Http/Databases/Get.php | 2 +- .../Databases/Http/Databases/Logs/XList.php | 2 +- .../Http/Databases/Transactions/Delete.php | 2 +- .../Http/Databases/Transactions/Get.php | 2 +- .../Transactions/Operations/Create.php | 8 +++--- .../Http/Databases/Transactions/Update.php | 4 +-- .../Databases/Http/Databases/Update.php | 2 +- .../Databases/Http/Databases/Usage/Get.php | 2 +- .../Databases/Http/TablesDB/Logs/XList.php | 2 +- 40 files changed, 124 insertions(+), 134 deletions(-) diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 27d2f62059..33c0942b2d 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -389,7 +389,8 @@ class Exception extends \Exception string $message = null, int|string $code = null, \Throwable $previous = null, - ?string $view = null + ?string $view = null, + array $params = [] ) { $this->errors = Config::getParam('errors'); $this->type = $type; @@ -405,30 +406,19 @@ class Exception extends \Exception } } - $this->message = $message ?? $this->errors[$type]['description']; + // Format message with params if provided + if (!empty($params) && $message === null) { + $description = $this->errors[$type]['description'] ?? ''; + $this->message = !empty($description) ? sprintf($description, ...$params) : ''; + } else { + $this->message = $message ?? $this->errors[$type]['description']; + } $this->publish = $this->errors[$type]['publish'] ?? ($this->code >= 500); parent::__construct($this->message, $this->code, $previous); } - /** - * Create an exception with formatted parameters. - */ - public static function withParams(string $type, mixed ...$params): self - { - $errors = Config::getParam('errors'); - $description = $errors[$type]['description'] ?? ''; - - if (!empty($params) && !empty($description)) { - $message = sprintf($description, ...$params); - } else { - $message = $description; - } - - return new self($type, $message); - } - /** * Get the type of the exception. * diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php index 3156d87b7f..83a401a35e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php @@ -307,19 +307,19 @@ abstract class Action extends UtopiaAction $options = $attribute->getAttribute('options', []); if (in_array($type, Database::SPATIAL_TYPES) && !$dbForProject->getAdapter()->getSupportForSpatialAttributes()) { - throw Exception::withParams($this->getSpatialTypeNotSupportedException(), $type); + throw new Exception($this->getSpatialTypeNotSupportedException(), params: [$type]); } $db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($db->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } if (!empty($format)) { @@ -382,9 +382,9 @@ abstract class Action extends UtopiaAction $dbForProject->checkAttribute($collection, $attribute); $attribute = $dbForProject->createDocument('attributes', $attribute); } catch (DuplicateException) { - throw Exception::withParams($this->getDuplicateException(), $key); + throw new Exception($this->getDuplicateException(), params: [$key]); } catch (LimitException) { - throw Exception::withParams($this->getLimitException(), $collectionId); + throw new Exception($this->getLimitException(), params: [$collectionId]); } catch (StructureException $e) { throw new Exception($this->getStructureException(), $e->getMessage()); } catch (Throwable $e) { @@ -426,9 +426,9 @@ abstract class Action extends UtopiaAction $dbForProject->checkAttribute($relatedCollection, $twoWayAttribute); $dbForProject->createDocument('attributes', $twoWayAttribute); } catch (DuplicateException) { - throw Exception::withParams($this->getDuplicateException(), $twoWayKey); + throw new Exception($this->getDuplicateException(), params: [$twoWayKey]); } catch (LimitException) { - throw Exception::withParams($this->getLimitException(), $relatedCollection->getId()); + throw new Exception($this->getLimitException(), params: [$relatedCollection->getId()]); } catch (StructureException) { throw new Exception($this->getStructureException()); } catch (Throwable $e) { @@ -477,19 +477,19 @@ abstract class Action extends UtopiaAction $db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($db->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } $attribute = $dbForProject->getDocument('attributes', $db->getSequence() . '_' . $collection->getSequence() . '_' . $key); if ($attribute->isEmpty()) { - throw Exception::withParams($this->getNotFoundException(), $key); + throw new Exception($this->getNotFoundException(), params: [$key]); } if ($attribute->getAttribute('status') !== 'available') { @@ -590,7 +590,7 @@ abstract class Action extends UtopiaAction } catch (IndexException) { throw new Exception(Exception::INDEX_INVALID); } catch (LimitException) { - throw Exception::withParams($this->getLimitException(), $collectionId); + throw new Exception($this->getLimitException(), params: [$collectionId]); } catch (RelationshipException $e) { throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage()); } catch (StructureException $e) { @@ -624,11 +624,11 @@ abstract class Action extends UtopiaAction newKey: $newKey ?? null ); } catch (DuplicateException) { - throw Exception::withParams($this->getDuplicateException(), $key); + throw new Exception($this->getDuplicateException(), params: [$key]); } catch (IndexException $e) { throw new Exception($this->getInvalidIndexException(), $e->getMessage()); } catch (LimitException) { - throw Exception::withParams($this->getLimitException(), $collectionId); + throw new Exception($this->getLimitException(), params: [$collectionId]); } catch (TruncateException) { throw new Exception($this->getInvalidResizeException()); } @@ -644,7 +644,7 @@ abstract class Action extends UtopiaAction try { $dbForProject->updateDocument('attributes', $originalUid, $attribute); } catch (DuplicateException) { - throw Exception::withParams($this->getDuplicateException(), $newKey); + throw new Exception($this->getDuplicateException(), params: [$newKey]); } /** diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php index eff1dfe781..23c21fecee 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php @@ -74,17 +74,17 @@ class Delete extends Action { $db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($db->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } $attribute = $dbForProject->getDocument('attributes', $db->getSequence() . '_' . $collection->getSequence() . '_' . $key); if ($attribute->isEmpty()) { - throw Exception::withParams($this->getNotFoundException(), $key); + throw new Exception($this->getNotFoundException(), params: [$key]); } $validator = new IndexDependencyValidator( @@ -93,7 +93,7 @@ class Delete extends Action ); if (!$validator->isValid($attribute)) { - throw Exception::withParams($this->getIndexDependencyException(), $key); + throw new Exception($this->getIndexDependencyException(), params: [$key]); } if ($attribute->getAttribute('status') === 'available') { @@ -108,12 +108,12 @@ class Delete extends Action if ($options['twoWay']) { $relatedCollection = $dbForProject->getDocument('database_' . $db->getSequence(), $options['relatedCollection']); if ($relatedCollection->isEmpty()) { - throw Exception::withParams($this->getParentNotFoundException(), $options['relatedCollection']); + throw new Exception($this->getParentNotFoundException(), params: [$options['relatedCollection']]); } $relatedAttribute = $dbForProject->getDocument('attributes', $db->getSequence() . '_' . $relatedCollection->getSequence() . '_' . $options['twoWayKey']); if ($relatedAttribute->isEmpty()) { - throw Exception::withParams($this->getNotFoundException(), $options['twoWayKey']); + throw new Exception($this->getNotFoundException(), params: [$options['twoWayKey']]); } if ($relatedAttribute->getAttribute('status') === 'available') { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php index f0ee593a51..c11dd1c63b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php @@ -75,17 +75,17 @@ class Get extends Action { $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } $attribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $collection->getSequence() . '_' . $key); if ($attribute->isEmpty()) { - throw Exception::withParams($this->getNotFoundException(), $key); + throw new Exception($this->getNotFoundException(), params: [$key]); } $type = $attribute->getAttribute('type'); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php index ecfa284c27..5606c63a08 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php @@ -93,19 +93,19 @@ class Create extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); $collection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence()); if ($collection->isEmpty()) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } $relatedCollectionDocument = $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId); $relatedCollection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $relatedCollectionDocument->getSequence()); if ($relatedCollection->isEmpty()) { - throw Exception::withParams($this->getParentNotFoundException(), $relatedCollectionId); + throw new Exception($this->getParentNotFoundException(), params: [$relatedCollectionId]); } $attributes = $collection->getAttribute('attributes', []); @@ -115,14 +115,14 @@ class Create extends Action } if (\strtolower($attribute->getId()) === \strtolower($key)) { - throw Exception::withParams($this->getDuplicateException(), $key); + throw new Exception($this->getDuplicateException(), params: [$key]); } if ( \strtolower($attribute->getAttribute('options')['twoWayKey']) === \strtolower($twoWayKey) && $attribute->getAttribute('options')['relatedCollection'] === $relatedCollection->getId() ) { - throw Exception::withParams($this->getDuplicateException(), $twoWayKey); + throw new Exception($this->getDuplicateException(), params: [$twoWayKey]); } if ( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php index 2279500bca..065cb333db 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php @@ -71,12 +71,12 @@ class XList extends Action { $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php index 8e23136394..d285c1ac13 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php @@ -93,7 +93,7 @@ class Create extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collectionId = $collectionId === 'unique()' ? ID::unique() : $collectionId; @@ -113,11 +113,11 @@ class Create extends Action 'search' => \implode(' ', [$collectionId, $name]), ])); } catch (DuplicateException) { - throw Exception::withParams($this->getDuplicateException(), $collectionId); + throw new Exception($this->getDuplicateException(), params: [$collectionId]); } catch (LimitException) { - throw Exception::withParams($this->getLimitException(), $databaseId); + throw new Exception($this->getLimitException(), params: [$databaseId]); } catch (NotFoundException) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collectionKey = 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(); @@ -205,13 +205,13 @@ class Create extends Action ); } catch (DuplicateException) { $dbForProject->deleteDocument($databaseKey, $collection->getId()); - throw Exception::withParams($this->getDuplicateException(), $collectionId); + throw new Exception($this->getDuplicateException(), params: [$collectionId]); } catch (IndexException $e) { $dbForProject->deleteDocument($databaseKey, $collection->getId()); throw new Exception($this->getInvalidIndexException(), $e->getMessage()); } catch (LimitException) { $dbForProject->deleteDocument($databaseKey, $collection->getId()); - throw Exception::withParams($this->getLimitException(), $collectionId); + throw new Exception($this->getLimitException(), params: [$collectionId]); } catch (\Throwable $e) { $dbForProject->deleteDocument($databaseKey, $collection->getId()); throw $e; @@ -227,7 +227,7 @@ class Create extends Action } } catch (DuplicateException) { $this->cleanup($dbForProject, $databaseKey, $collectionKey, $collection->getId()); - throw Exception::withParams($this->getDuplicateException(), $collectionId); + throw new Exception($this->getDuplicateException(), params: [$collectionId]); } catch (\Throwable $e) { $this->cleanup($dbForProject, $databaseKey, $collectionKey, $collection->getId()); throw $e; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php index a43e4dc687..bf0f83bb11 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php @@ -71,12 +71,12 @@ class Delete extends Action { $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw Exception::withParams($this->getNotFoundException(), $collectionId); + throw new Exception($this->getNotFoundException(), params: [$collectionId]); } if (!$dbForProject->deleteDocument('database_' . $database->getSequence(), $collectionId)) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php index daa3f92e7b..38e7f8f231 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php @@ -95,12 +95,12 @@ class Decrement extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty()) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } // Handle transaction staging diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php index 544e9f233d..10dadae824 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php @@ -95,12 +95,12 @@ class Increment extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty()) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } // Handle transaction staging diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php index f9af8af9e3..070ee09450 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php @@ -88,12 +88,12 @@ class Delete extends Action { $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } $hasRelationships = \array_filter( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php index ef065da1f8..2d55cd54f4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php @@ -100,12 +100,12 @@ class Update extends Action $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } if ($transactionId === null) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php index b80694d4f2..45db6cc96b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php @@ -90,12 +90,12 @@ class Upsert extends Action { $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } $hasRelationships = \array_filter( @@ -180,7 +180,7 @@ class Upsert extends Action } catch (ConflictException) { throw new Exception($this->getConflictException()); } catch (DuplicateException) { - throw Exception::withParams($this->getDuplicateException(), 'multiple'); + throw new Exception($this->getDuplicateException(), params: ['multiple']); } catch (RelationshipException $e) { throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage()); } catch (StructureException $e) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php index f38df32b30..a7fb81a486 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php @@ -187,12 +187,12 @@ class Create extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } $hasRelationships = \array_filter( @@ -372,7 +372,7 @@ class Create extends Action ? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId)) : $dbForProject->getDocument('transactions', $transactionId); if ($transaction->isEmpty()) { - throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId); + throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]); } if ($transaction->getAttribute('status', '') !== 'pending') { throw new Exception(Exception::TRANSACTION_NOT_READY); @@ -444,9 +444,9 @@ class Create extends Action ) ); } catch (DuplicateException) { - throw Exception::withParams($this->getDuplicateException(), $documentId); + throw new Exception($this->getDuplicateException(), params: [$documentId]); } catch (NotFoundException) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } catch (RelationshipException $e) { throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage()); } catch (StructureException $e) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php index c83510ed29..14a51c0fac 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php @@ -105,13 +105,13 @@ class Delete extends Action $isPrivilegedUser = User::isPrivileged(Authorization::getRoles()); if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } // Read permission should not be required for delete @@ -125,7 +125,7 @@ class Delete extends Action } if ($document->isEmpty()) { - throw Exception::withParams($this->getNotFoundException(), $documentId); + throw new Exception($this->getNotFoundException(), params: [$documentId]); } // Handle transaction staging @@ -134,7 +134,7 @@ class Delete extends Action ? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId)) : $dbForProject->getDocument('transactions', $transactionId); if ($transaction->isEmpty()) { - throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId); + throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]); } if ($transaction->getAttribute('status', '') !== 'pending') { throw new Exception(Exception::TRANSACTION_NOT_READY); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php index 8e80f1ddb1..62919488e6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php @@ -80,13 +80,13 @@ class Get extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } try { @@ -114,7 +114,7 @@ class Get extends Action } if ($document->isEmpty()) { - throw Exception::withParams($this->getNotFoundException(), $documentId); + throw new Exception($this->getNotFoundException(), params: [$documentId]); } $operations = 0; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php index 7b1447f3c3..47f5247831 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php @@ -79,17 +79,17 @@ class XList extends Action { $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } $document = $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId); if ($document->isEmpty()) { - throw Exception::withParams($this->getNotFoundException(), $documentId); + throw new Exception($this->getNotFoundException(), params: [$documentId]); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php index 165f256941..d2b67665a7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php @@ -104,13 +104,13 @@ class Update extends Action $isPrivilegedUser = User::isPrivileged(Authorization::getRoles()); if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } if ($transactionId === null) { @@ -129,7 +129,7 @@ class Update extends Action } if ($document->isEmpty()) { - throw Exception::withParams($this->getNotFoundException(), $documentId); + throw new Exception($this->getNotFoundException(), params: [$documentId]); } // Map aggregate permissions into the multiple permissions they represent. @@ -252,7 +252,7 @@ class Update extends Action ? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId)) : $dbForProject->getDocument('transactions', $transactionId); if ($transaction->isEmpty()) { - throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId); + throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]); } if ($transaction->getAttribute('status', '') !== 'pending') { throw new Exception(Exception::TRANSACTION_NOT_READY); @@ -326,7 +326,7 @@ class Update extends Action } catch (ConflictException) { throw new Exception($this->getConflictException()); } catch (DuplicateException) { - throw Exception::withParams($this->getDuplicateException(), $documentId); + throw new Exception($this->getDuplicateException(), params: [$documentId]); } catch (RelationshipException $e) { throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage()); } catch (StructureException $e) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php index 7ff78bf913..d85fb17842 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php @@ -111,12 +111,12 @@ class Upsert extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } if ($transactionId === null) { @@ -262,7 +262,7 @@ class Upsert extends Action ? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId)) : $dbForProject->getDocument('transactions', $transactionId); if ($transaction->isEmpty()) { - throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId); + throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]); } if ($transaction->getAttribute('status', '') !== 'pending') { throw new Exception(Exception::TRANSACTION_NOT_READY); @@ -335,7 +335,7 @@ class Upsert extends Action } catch (ConflictException) { throw new Exception($this->getConflictException()); } catch (DuplicateException) { - throw Exception::withParams($this->getDuplicateException(), $documentId); + throw new Exception($this->getDuplicateException(), params: [$documentId]); } catch (RelationshipException $e) { throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage()); } catch (StructureException $e) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php index 43f56d694e..b14a4f9983 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php @@ -84,12 +84,12 @@ class XList extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId)); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw Exception::withParams($this->getParentNotFoundException(), $collectionId); + throw new Exception($this->getParentNotFoundException(), params: [$collectionId]); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php index 1ff71110bf..22d1333cc4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php @@ -65,13 +65,13 @@ class Get extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw Exception::withParams($this->getNotFoundException(), $collectionId); + throw new Exception($this->getNotFoundException(), params: [$collectionId]); } $response->dynamic($collection, $this->getResponseModel()); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php index 0f1b473bea..b132aff8ef 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php @@ -87,14 +87,14 @@ class Create extends Action $db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($db->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId); if ($collection->isEmpty()) { // table or collection. - throw Exception::withParams($this->getGrandParentNotFoundException(), $collectionId); + throw new Exception($this->getGrandParentNotFoundException(), params: [$collectionId]); } $count = $dbForProject->count('indexes', [ @@ -105,7 +105,7 @@ class Create extends Action $limit = $dbForProject->getLimitForIndexes(); if ($count >= $limit) { - throw Exception::withParams($this->getLimitException(), $collectionId); + throw new Exception($this->getLimitException(), params: [$collectionId]); } $oldAttributes = \array_map( @@ -148,7 +148,7 @@ class Create extends Action $attributeIndex = \array_search($attribute, array_column($oldAttributes, 'key')); if ($attributeIndex === false) { - throw Exception::withParams($this->getParentUnknownException(), $attribute); + throw new Exception($this->getParentUnknownException(), params: [$attribute]); } $attributeStatus = $oldAttributes[$attributeIndex]['status']; @@ -160,7 +160,7 @@ class Create extends Action } if ($attributeStatus !== 'available') { - throw Exception::withParams($this->getParentNotAvailableException(), $oldAttributes[$attributeIndex]['key']); + throw new Exception($this->getParentNotAvailableException(), params: [$oldAttributes[$attributeIndex]['key']]); } if (empty($lengths[$i])) { @@ -208,7 +208,7 @@ class Create extends Action try { $index = $dbForProject->createDocument('indexes', $index); } catch (DuplicateException) { - throw Exception::withParams($this->getDuplicateException(), $key); + throw new Exception($this->getDuplicateException(), params: [$key]); } $dbForProject->purgeCachedDocument('database_' . $db->getSequence(), $collectionId); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php index b9caeb3720..57198cc53c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php @@ -78,19 +78,19 @@ class Delete extends Action $db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($db->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId); if ($collection->isEmpty()) { // table or collection. - throw Exception::withParams($this->getGrandParentNotFoundException(), $collectionId); + throw new Exception($this->getGrandParentNotFoundException(), params: [$collectionId]); } $index = $dbForProject->getDocument('indexes', $db->getSequence() . '_' . $collection->getSequence() . '_' . $key); if (empty($index->getId())) { - throw Exception::withParams($this->getNotFoundException(), $key); + throw new Exception($this->getNotFoundException(), params: [$key]); } // Only update status if removing available index diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php index c16ac12a91..c03e80dedc 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php @@ -67,18 +67,18 @@ class Get extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { // table or collection. - throw Exception::withParams($this->getGrandParentNotFoundException(), $collectionId); + throw new Exception($this->getGrandParentNotFoundException(), params: [$collectionId]); } $index = $collection->find('key', $key, 'indexes'); if (empty($index)) { - throw Exception::withParams($this->getNotFoundException(), $key); + throw new Exception($this->getNotFoundException(), params: [$key]); } $response->dynamic($index, $this->getResponseModel()); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php index 38213ee4c1..ec4bc94a66 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php @@ -75,14 +75,14 @@ class XList extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { // table or collection. - throw Exception::withParams($this->getGrandParentNotFoundException(), $collectionId); + throw new Exception($this->getGrandParentNotFoundException(), params: [$collectionId]); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php index 7d0b1ab67f..a45daa32a4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php @@ -79,14 +79,14 @@ class XList extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collectionDocument = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); $collection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $collectionDocument->getSequence()); if ($collection->isEmpty()) { - throw Exception::withParams($this->getNotFoundException(), $collectionId); + throw new Exception($this->getNotFoundException(), params: [$collectionId]); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php index f1b78bf7c2..bbad2a7f22 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php @@ -78,12 +78,12 @@ class Update extends Action { $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); if ($collection->isEmpty()) { - throw Exception::withParams($this->getNotFoundException(), $collectionId); + throw new Exception($this->getNotFoundException(), params: [$collectionId]); } $permissions ??= $collection->getPermissions(); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php index d270bc5efc..c4a46650c9 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php @@ -73,7 +73,7 @@ class Get extends Action $collection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $collectionDocument->getSequence()); if ($collection->isEmpty()) { - throw Exception::withParams($this->getNotFoundException(), $collectionId); + throw new Exception($this->getNotFoundException(), params: [$collectionId]); } $periods = Config::getParam('usage', []); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php index 9430394a19..e1985b0fa9 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php @@ -75,7 +75,7 @@ class XList extends Action $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php index 7c8d75a2d1..009b499ea8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php @@ -84,7 +84,7 @@ class Create extends Action 'type' => $this->getDatabaseType(), ])); } catch (DuplicateException) { - throw Exception::withParams(Exception::DATABASE_ALREADY_EXISTS, $databaseId); + throw new Exception(Exception::DATABASE_ALREADY_EXISTS, params: [$databaseId]); } catch (StructureException $e) { throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $e->getMessage()); } @@ -109,13 +109,13 @@ class Create extends Action try { $dbForProject->createCollection('database_' . $database->getSequence(), $attributes, $indexes); } catch (DuplicateException) { - throw Exception::withParams(Exception::DATABASE_ALREADY_EXISTS, $databaseId); + throw new Exception(Exception::DATABASE_ALREADY_EXISTS, params: [$databaseId]); } catch (IndexException $e) { throw new Exception(Exception::INDEX_INVALID); } catch (LimitException) { // TODO: @Jake, how do we handle this collection/table? // there's no context awareness at this level on what the api is. - throw Exception::withParams(Exception::COLLECTION_LIMIT_EXCEEDED, $databaseId); + throw new Exception(Exception::COLLECTION_LIMIT_EXCEEDED, params: [$databaseId]); } $queueForEvents->setParam('databaseId', $database->getId()); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php index c181b9ac45..76b36b5df9 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php @@ -69,7 +69,7 @@ class Delete extends Action $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } if (!$dbForProject->deleteDocument('databases', $databaseId)) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php index 33c11efbda..2eb09955c1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php @@ -61,7 +61,7 @@ class Get extends Action $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $response->dynamic($database, UtopiaResponse::MODEL_DATABASE); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php index 0a496f9b9e..a794ec325e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php @@ -75,7 +75,7 @@ class XList extends Action $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Delete.php index d799ccc200..b018743f36 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Delete.php @@ -60,7 +60,7 @@ class Delete extends Action $transaction = $dbForProject->getDocument('transactions', $transactionId); if ($transaction->isEmpty()) { - throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId); + throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]); } $dbForProject->deleteDocument('transactions', $transactionId); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php index 3b153fd0a4..78d19ec4eb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php @@ -58,7 +58,7 @@ class Get extends Action $transaction = $dbForProject->getDocument('transactions', $transactionId); if ($transaction->isEmpty()) { - throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId); + throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]); } $response diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php index 545031698f..765e663911 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php @@ -80,7 +80,7 @@ class Create extends Action ? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId)) : $dbForProject->getDocument('transactions', $transactionId); if ($transaction->isEmpty()) { - throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId); + throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]); } if ($transaction->getAttribute('status', '') !== 'pending') { throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Invalid or non‑pending transaction'); @@ -115,14 +115,14 @@ class Create extends Action $database = $databases[$operation['databaseId']] ??= Authorization::skip(fn () => $dbForProject->getDocument('databases', $operation['databaseId'])); if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $operation['databaseId']); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$operation['databaseId']]); } $collection = $collections[$operation[$this->getGroupId()]] ??= Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $operation[$this->getGroupId()])); if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { - throw Exception::withParams(Exception::COLLECTION_NOT_FOUND, $operation[$this->getGroupId()]); + throw new Exception(Exception::COLLECTION_NOT_FOUND, params: [$operation[$this->getGroupId()]]); } if (\in_array($operation['action'], ['bulkCreate', 'bulkUpdate', 'bulkUpsert', 'bulkDelete'])) { @@ -148,7 +148,7 @@ class Create extends Action $document = $transactionState->getDocument($collectionKey, $documentId, $transactionId); if ($document->isEmpty() && !$isDependant && $operation['action'] !== 'upsert') { - throw Exception::withParams(Exception::DOCUMENT_NOT_FOUND, $documentId); + throw new Exception(Exception::DOCUMENT_NOT_FOUND, params: [$documentId]); } } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php index df9b6f895a..70e670144d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php @@ -118,7 +118,7 @@ class Update extends Action ? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId)) : $dbForProject->getDocument('transactions', $transactionId); if ($transaction->isEmpty()) { - throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId); + throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]); } if ($transaction->getAttribute('status', '') !== 'pending') { throw new Exception(Exception::TRANSACTION_NOT_READY); @@ -247,7 +247,7 @@ class Update extends Action 'status' => 'failed', ]))); - throw Exception::withParams(Exception::DOCUMENT_NOT_FOUND, $currentDocumentId ?? 'unknown', previous: $e); + throw new Exception(Exception::DOCUMENT_NOT_FOUND, previous: $e, params: [$currentDocumentId ?? 'unknown']); } catch (DuplicateException | ConflictException $e) { Authorization::skip(fn () => $dbForProject->updateDocument('transactions', $transactionId, new Document([ 'status' => 'failed', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php index 4030040ee3..9f2ce06db4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php @@ -70,7 +70,7 @@ class Update extends Action $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $database = $dbForProject->updateDocument('databases', $databaseId, $database diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php index ce0d1ad16d..a717b00ae4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php @@ -67,7 +67,7 @@ class Get extends Action $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $periods = Config::getParam('usage', []); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php index ce1bc35e75..53476dbae1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php @@ -70,7 +70,7 @@ class XList extends Action $database = $dbForProject->getDocument('databases', $databaseId); if ($database->isEmpty()) { - throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId); + throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } try { From 102d3fd2455af30965ca58033415c299b6fb9a45 Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 11 Dec 2025 16:08:13 +0530 Subject: [PATCH 3/3] fix: tests. --- .../Collections/Attributes/Relationship/Create.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php index 5606c63a08..76cc17e2f7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php @@ -89,6 +89,7 @@ class Create extends Action public function action(string $databaseId, string $collectionId, string $relatedCollectionId, string $type, bool $twoWay, ?string $key, ?string $twoWayKey, string $onDelete, UtopiaResponse $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents): void { $key ??= $relatedCollectionId; + $twoWayKeyWasProvided = $twoWayKey !== null; $twoWayKey ??= $collectionId; $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); @@ -122,7 +123,10 @@ class Create extends Action \strtolower($attribute->getAttribute('options')['twoWayKey']) === \strtolower($twoWayKey) && $attribute->getAttribute('options')['relatedCollection'] === $relatedCollection->getId() ) { - throw new Exception($this->getDuplicateException(), params: [$twoWayKey]); + // If user explicitly provided twoWayKey, report that. + // Otherwise report the key that they're trying to create. + $conflictingKey = $twoWayKeyWasProvided ? $twoWayKey : $key; + throw new Exception($this->getDuplicateException(), params: [$conflictingKey]); } if (