Merge pull request #10934 from appwrite/database-errors

This commit is contained in:
Darshan 2025-12-11 16:58:35 +05:30 committed by GitHub
commit 72f86ce5ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
49 changed files with 182 additions and 167 deletions

View file

@ -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 => [

View file

@ -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,7 +406,13 @@ 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);

View file

@ -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 new Exception($this->getSpatialTypeNotSupportedException(), params: [$type]);
}
$db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($db->isEmpty()) {
throw new Exception(Exception::DATABASE_NOT_FOUND);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw new Exception($this->getParentNotFoundException());
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 new Exception($this->getDuplicateException());
throw new Exception($this->getDuplicateException(), params: [$key]);
} catch (LimitException) {
throw new Exception($this->getLimitException());
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 new Exception($this->getDuplicateException());
throw new Exception($this->getDuplicateException(), params: [$twoWayKey]);
} catch (LimitException) {
throw new Exception($this->getLimitException());
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 new Exception(Exception::DATABASE_NOT_FOUND);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw new Exception($this->getParentNotFoundException());
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
$attribute = $dbForProject->getDocument('attributes', $db->getSequence() . '_' . $collection->getSequence() . '_' . $key);
if ($attribute->isEmpty()) {
throw new Exception($this->getNotFoundException());
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 new Exception($this->getLimitException());
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 new Exception($this->getDuplicateException());
throw new Exception($this->getDuplicateException(), params: [$key]);
} catch (IndexException $e) {
throw new Exception($this->getInvalidIndexException(), $e->getMessage());
} catch (LimitException) {
throw new Exception($this->getLimitException());
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 new Exception($this->getDuplicateException());
throw new Exception($this->getDuplicateException(), params: [$newKey]);
}
/**

View file

@ -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 new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw new Exception($this->getParentNotFoundException());
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
$attribute = $dbForProject->getDocument('attributes', $db->getSequence() . '_' . $collection->getSequence() . '_' . $key);
if ($attribute->isEmpty()) {
throw new Exception($this->getNotFoundException());
throw new Exception($this->getNotFoundException(), params: [$key]);
}
$validator = new IndexDependencyValidator(
@ -93,7 +93,7 @@ class Delete extends Action
);
if (!$validator->isValid($attribute)) {
throw new Exception($this->getIndexDependencyException());
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 new Exception($this->getParentNotFoundException());
throw new Exception($this->getParentNotFoundException(), params: [$options['relatedCollection']]);
}
$relatedAttribute = $dbForProject->getDocument('attributes', $db->getSequence() . '_' . $relatedCollection->getSequence() . '_' . $options['twoWayKey']);
if ($relatedAttribute->isEmpty()) {
throw new Exception($this->getNotFoundException());
throw new Exception($this->getNotFoundException(), params: [$options['twoWayKey']]);
}
if ($relatedAttribute->getAttribute('status') === 'available') {

View file

@ -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 new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw new Exception($this->getParentNotFoundException());
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
$attribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $collection->getSequence() . '_' . $key);
if ($attribute->isEmpty()) {
throw new Exception($this->getNotFoundException());
throw new Exception($this->getNotFoundException(), params: [$key]);
}
$type = $attribute->getAttribute('type');

View file

@ -89,23 +89,24 @@ 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));
if ($database->isEmpty()) {
throw new Exception(Exception::DATABASE_NOT_FOUND);
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 new Exception($this->getParentNotFoundException());
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 new Exception($this->getParentNotFoundException());
throw new Exception($this->getParentNotFoundException(), params: [$relatedCollectionId]);
}
$attributes = $collection->getAttribute('attributes', []);
@ -115,14 +116,17 @@ class Create extends Action
}
if (\strtolower($attribute->getId()) === \strtolower($key)) {
throw new Exception($this->getDuplicateException());
throw new Exception($this->getDuplicateException(), params: [$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.');
// 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 (

View file

@ -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 new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw new Exception($this->getParentNotFoundException());
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
try {

View file

@ -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 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 new Exception($this->getDuplicateException());
throw new Exception($this->getDuplicateException(), params: [$collectionId]);
} catch (LimitException) {
throw new Exception($this->getLimitException());
throw new Exception($this->getLimitException(), params: [$databaseId]);
} catch (NotFoundException) {
throw new Exception(Exception::DATABASE_NOT_FOUND);
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 new Exception($this->getDuplicateException());
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 new Exception($this->getLimitException());
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 new Exception($this->getDuplicateException());
throw new Exception($this->getDuplicateException(), params: [$collectionId]);
} catch (\Throwable $e) {
$this->cleanup($dbForProject, $databaseKey, $collectionKey, $collection->getId());
throw $e;

View file

@ -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 new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw new Exception($this->getNotFoundException());
throw new Exception($this->getNotFoundException(), params: [$collectionId]);
}
if (!$dbForProject->deleteDocument('database_' . $database->getSequence(), $collectionId)) {

View file

@ -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 new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId));
if ($collection->isEmpty()) {
throw new Exception($this->getParentNotFoundException());
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
// Handle transaction staging

View file

@ -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 new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId));
if ($collection->isEmpty()) {
throw new Exception($this->getParentNotFoundException());
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
// Handle transaction staging

View file

@ -88,12 +88,12 @@ class Delete extends Action
{
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw new Exception(Exception::DATABASE_NOT_FOUND);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw new Exception($this->getParentNotFoundException());
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
$hasRelationships = \array_filter(

View file

@ -100,12 +100,12 @@ class Update extends Action
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw new Exception(Exception::DATABASE_NOT_FOUND);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw new Exception($this->getParentNotFoundException());
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
if ($transactionId === null) {

View file

@ -90,12 +90,12 @@ class Upsert extends Action
{
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw new Exception(Exception::DATABASE_NOT_FOUND);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw new Exception($this->getParentNotFoundException());
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 new Exception($this->getDuplicateException());
throw new Exception($this->getDuplicateException(), params: ['multiple']);
} catch (RelationshipException $e) {
throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage());
} catch (StructureException $e) {

View file

@ -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 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 new Exception($this->getParentNotFoundException());
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 new Exception(Exception::TRANSACTION_NOT_FOUND);
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 new Exception($this->getDuplicateException());
throw new Exception($this->getDuplicateException(), params: [$documentId]);
} catch (NotFoundException) {
throw new Exception($this->getParentNotFoundException());
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
} catch (RelationshipException $e) {
throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage());
} catch (StructureException $e) {

View file

@ -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 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 new Exception($this->getParentNotFoundException());
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 new Exception($this->getNotFoundException());
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 new Exception(Exception::TRANSACTION_NOT_FOUND);
throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]);
}
if ($transaction->getAttribute('status', '') !== 'pending') {
throw new Exception(Exception::TRANSACTION_NOT_READY);

View file

@ -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 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 new Exception($this->getParentNotFoundException());
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
try {
@ -114,7 +114,7 @@ class Get extends Action
}
if ($document->isEmpty()) {
throw new Exception($this->getNotFoundException());
throw new Exception($this->getNotFoundException(), params: [$documentId]);
}
$operations = 0;

View file

@ -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 new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw new Exception($this->getParentNotFoundException());
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
$document = $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId);
if ($document->isEmpty()) {
throw new Exception($this->getNotFoundException());
throw new Exception($this->getNotFoundException(), params: [$documentId]);
}
try {

View file

@ -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 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 new Exception($this->getParentNotFoundException());
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
if ($transactionId === null) {
@ -129,7 +129,7 @@ class Update extends Action
}
if ($document->isEmpty()) {
throw new Exception($this->getNotFoundException());
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 new Exception(Exception::TRANSACTION_NOT_FOUND);
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 new Exception($this->getDuplicateException());
throw new Exception($this->getDuplicateException(), params: [$documentId]);
} catch (RelationshipException $e) {
throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage());
} catch (StructureException $e) {

View file

@ -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 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 new Exception($this->getParentNotFoundException());
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 new Exception(Exception::TRANSACTION_NOT_FOUND);
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 new Exception($this->getDuplicateException());
throw new Exception($this->getDuplicateException(), params: [$documentId]);
} catch (RelationshipException $e) {
throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage());
} catch (StructureException $e) {

View file

@ -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 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 new Exception($this->getParentNotFoundException());
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
try {

View file

@ -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 new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw new Exception($this->getNotFoundException());
throw new Exception($this->getNotFoundException(), params: [$collectionId]);
}
$response->dynamic($collection, $this->getResponseModel());

View file

@ -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 new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId);
if ($collection->isEmpty()) {
// table or collection.
throw new Exception($this->getGrandParentNotFoundException());
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 new Exception($this->getLimitException(), 'Index limit exceeded');
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 new Exception($this->getParentUnknownException(), "Unknown $contextType: " . $attribute . ". Verify the $contextType name or create the $contextType.");
throw new Exception($this->getParentUnknownException(), params: [$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 new Exception($this->getParentNotAvailableException(), params: [$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 new Exception($this->getDuplicateException(), params: [$key]);
}
$dbForProject->purgeCachedDocument('database_' . $db->getSequence(), $collectionId);

View file

@ -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 new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId);
if ($collection->isEmpty()) {
// table or collection.
throw new Exception($this->getGrandParentNotFoundException());
throw new Exception($this->getGrandParentNotFoundException(), params: [$collectionId]);
}
$index = $dbForProject->getDocument('indexes', $db->getSequence() . '_' . $collection->getSequence() . '_' . $key);
if (empty($index->getId())) {
throw new Exception($this->getNotFoundException());
throw new Exception($this->getNotFoundException(), params: [$key]);
}
// Only update status if removing available index

View file

@ -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 new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
// table or collection.
throw new Exception($this->getGrandParentNotFoundException());
throw new Exception($this->getGrandParentNotFoundException(), params: [$collectionId]);
}
$index = $collection->find('key', $key, 'indexes');
if (empty($index)) {
throw new Exception($this->getNotFoundException());
throw new Exception($this->getNotFoundException(), params: [$key]);
}
$response->dynamic($index, $this->getResponseModel());

View file

@ -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 new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
// table or collection.
throw new Exception($this->getGrandParentNotFoundException());
throw new Exception($this->getGrandParentNotFoundException(), params: [$collectionId]);
}
try {

View file

@ -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 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 new Exception($this->getNotFoundException());
throw new Exception($this->getNotFoundException(), params: [$collectionId]);
}
try {

View file

@ -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 new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw new Exception($this->getNotFoundException());
throw new Exception($this->getNotFoundException(), params: [$collectionId]);
}
$permissions ??= $collection->getPermissions();

View file

@ -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 new Exception($this->getNotFoundException(), params: [$collectionId]);
}
$periods = Config::getParam('usage', []);

View file

@ -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 new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
try {

View file

@ -84,7 +84,7 @@ class Create extends Action
'type' => $this->getDatabaseType(),
]));
} catch (DuplicateException) {
throw new Exception(Exception::DATABASE_ALREADY_EXISTS);
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 new Exception(Exception::DATABASE_ALREADY_EXISTS);
} catch (IndexException) {
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 new Exception(Exception::COLLECTION_LIMIT_EXCEEDED);
throw new Exception(Exception::COLLECTION_LIMIT_EXCEEDED, params: [$databaseId]);
}
$queueForEvents->setParam('databaseId', $database->getId());

View file

@ -69,7 +69,7 @@ class Delete extends Action
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw new Exception(Exception::DATABASE_NOT_FOUND);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
if (!$dbForProject->deleteDocument('databases', $databaseId)) {

View file

@ -61,7 +61,7 @@ class Get extends Action
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw new Exception(Exception::DATABASE_NOT_FOUND);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$response->dynamic($database, UtopiaResponse::MODEL_DATABASE);

View file

@ -75,7 +75,7 @@ class XList extends Action
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw new Exception(Exception::DATABASE_NOT_FOUND);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
try {

View file

@ -60,7 +60,7 @@ class Delete extends Action
$transaction = $dbForProject->getDocument('transactions', $transactionId);
if ($transaction->isEmpty()) {
throw new Exception(Exception::TRANSACTION_NOT_FOUND);
throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]);
}
$dbForProject->deleteDocument('transactions', $transactionId);

View file

@ -58,7 +58,7 @@ class Get extends Action
$transaction = $dbForProject->getDocument('transactions', $transactionId);
if ($transaction->isEmpty()) {
throw new Exception(Exception::TRANSACTION_NOT_FOUND);
throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]);
}
$response

View file

@ -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 new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]);
}
if ($transaction->getAttribute('status', '') !== 'pending') {
throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Invalid or nonpending 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 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 new Exception(Exception::COLLECTION_NOT_FOUND);
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 new Exception(Exception::DOCUMENT_NOT_FOUND);
throw new Exception(Exception::DOCUMENT_NOT_FOUND, params: [$documentId]);
}
}

View file

@ -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 new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$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 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',

View file

@ -70,7 +70,7 @@ class Update extends Action
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw new Exception(Exception::DATABASE_NOT_FOUND);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$database = $dbForProject->updateDocument('databases', $databaseId, $database

View file

@ -67,7 +67,7 @@ class Get extends Action
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw new Exception(Exception::DATABASE_NOT_FOUND);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$periods = Config::getParam('usage', []);

View file

@ -70,7 +70,7 @@ class XList extends Action
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw new Exception(Exception::DATABASE_NOT_FOUND);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
try {

View file

@ -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',

View file

@ -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

View file

@ -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',

View file

@ -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',

View file

@ -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

View file

@ -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',

View file

@ -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()

View file

@ -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()