Merge pull request #10318 from appwrite/fix-catches

Fix uncaught invalid arg
This commit is contained in:
Jake Barnby 2025-08-14 20:13:10 +12:00 committed by GitHub
commit 405aa7f4ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 20 deletions

View file

@ -4493,7 +4493,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents/:documen
App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:documentId/:attribute/increment')
->desc('Increment document attribute')
->groups(['api', 'database'])
->label('event', 'databases.[databaseId].collections.[collectionId].documents.[documentId].increment')
->label('event', 'databases.[databaseId].collections.[collectionId].documents.[documentId].update')
->label('scope', 'documents.write')
->label('resourceType', RESOURCE_TYPE_DATABASES)
->label('audits.event', 'documents.increment')
@ -4552,6 +4552,8 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum
throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED, 'Attribute "' . $attribute . '" has reached the maximum value of ' . $max);
} catch (TypeException) {
throw new Exception(Exception::ATTRIBUTE_TYPE_INVALID, 'Attribute "' . $attribute . '" is not a number');
} catch (InvalidArgumentException $e) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage());
}
$queueForStatsUsage
@ -4561,6 +4563,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum
$queueForEvents
->setParam('databaseId', $databaseId)
->setParam('collectionId', $collectionId)
->setParam('documentId', $document->getId())
->setContext('collection', $collection)
->setContext('database', $database);
@ -4570,7 +4573,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum
App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:documentId/:attribute/decrement')
->desc('Decrement document attribute')
->groups(['api', 'database'])
->label('event', 'databases.[databaseId].collections.[collectionId].documents.[documentId].decrement')
->label('event', 'databases.[databaseId].collections.[collectionId].documents.[documentId].update')
->label('scope', 'documents.write')
->label('resourceType', RESOURCE_TYPE_DATABASES)
->label('audits.event', 'documents.decrement')
@ -4629,6 +4632,8 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum
throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED, 'Attribute "' . $attribute . '" has reached the minimum value of ' . $min);
} catch (TypeException) {
throw new Exception(Exception::ATTRIBUTE_TYPE_INVALID, 'Attribute "' . $attribute . '" is not a number');
} catch (InvalidArgumentException $e) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage());
}
$queueForStatsUsage
@ -4638,6 +4643,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum
$queueForEvents
->setParam('databaseId', $databaseId)
->setParam('collectionId', $collectionId)
->setParam('documentId', $document->getId())
->setContext('collection', $collection)
->setContext('database', $database);

36
composer.lock generated
View file

@ -1228,16 +1228,16 @@
},
{
"name": "open-telemetry/context",
"version": "1.3.0",
"version": "1.3.1",
"source": {
"type": "git",
"url": "https://github.com/opentelemetry-php/context.git",
"reference": "4d5d98f1d4311a55b8d07e3d4c06d2430b4e6efc"
"reference": "438f71812242db3f196fb4c717c6f92cbc819be6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/opentelemetry-php/context/zipball/4d5d98f1d4311a55b8d07e3d4c06d2430b4e6efc",
"reference": "4d5d98f1d4311a55b8d07e3d4c06d2430b4e6efc",
"url": "https://api.github.com/repos/opentelemetry-php/context/zipball/438f71812242db3f196fb4c717c6f92cbc819be6",
"reference": "438f71812242db3f196fb4c717c6f92cbc819be6",
"shasum": ""
},
"require": {
@ -1283,7 +1283,7 @@
"issues": "https://github.com/open-telemetry/opentelemetry-php/issues",
"source": "https://github.com/open-telemetry/opentelemetry-php"
},
"time": "2025-08-04T03:25:06+00:00"
"time": "2025-08-13T01:12:00+00:00"
},
{
"name": "open-telemetry/exporter-otlp",
@ -3545,16 +3545,16 @@
},
{
"name": "utopia-php/database",
"version": "0.71.13",
"version": "0.71.14",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/database.git",
"reference": "43aaba72b5699a06351b25924c3417ff83e6bb4b"
"reference": "20998e268ec528ebbf06adb77ec4230f70469fa7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/database/zipball/43aaba72b5699a06351b25924c3417ff83e6bb4b",
"reference": "43aaba72b5699a06351b25924c3417ff83e6bb4b",
"url": "https://api.github.com/repos/utopia-php/database/zipball/20998e268ec528ebbf06adb77ec4230f70469fa7",
"reference": "20998e268ec528ebbf06adb77ec4230f70469fa7",
"shasum": ""
},
"require": {
@ -3595,9 +3595,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/database/issues",
"source": "https://github.com/utopia-php/database/tree/0.71.13"
"source": "https://github.com/utopia-php/database/tree/0.71.14"
},
"time": "2025-08-11T10:47:16+00:00"
"time": "2025-08-14T07:15:06+00:00"
},
{
"name": "utopia-php/detector",
@ -5440,16 +5440,16 @@
},
{
"name": "nikic/php-parser",
"version": "v5.6.0",
"version": "v5.6.1",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
"reference": "221b0d0fdf1369c71047ad1d18bb5880017bbc56"
"reference": "f103601b29efebd7ff4a1ca7b3eeea9e3336a2a2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/221b0d0fdf1369c71047ad1d18bb5880017bbc56",
"reference": "221b0d0fdf1369c71047ad1d18bb5880017bbc56",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/f103601b29efebd7ff4a1ca7b3eeea9e3336a2a2",
"reference": "f103601b29efebd7ff4a1ca7b3eeea9e3336a2a2",
"shasum": ""
},
"require": {
@ -5468,7 +5468,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "5.0-dev"
"dev-master": "5.x-dev"
}
},
"autoload": {
@ -5492,9 +5492,9 @@
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
"source": "https://github.com/nikic/PHP-Parser/tree/v5.6.0"
"source": "https://github.com/nikic/PHP-Parser/tree/v5.6.1"
},
"time": "2025-07-27T20:03:57+00:00"
"time": "2025-08-13T20:13:15+00:00"
},
{
"name": "phar-io/manifest",

View file

@ -5569,6 +5569,15 @@ trait DatabasesBase
'x-appwrite-project' => $this->getProject()['$id'],
]));
$this->assertEquals(404, $notFound['headers']['status-code']);
// Test increment with value 0
$inc3 = $this->client->call(Client::METHOD_PATCH, "/databases/$databaseId/collections/$collectionId/documents/$docId/count/increment", array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
]), [
'value' => 0
]);
$this->assertEquals(400, $inc3['headers']['status-code']);
}
public function testDecrementAttribute(): void
@ -5690,6 +5699,15 @@ trait DatabasesBase
'x-appwrite-project' => $this->getProject()['$id'],
]), ['value' => 'not-a-number']);
$this->assertEquals(400, $typeErr['headers']['status-code']);
// Test decrement with value 0
$inc3 = $this->client->call(Client::METHOD_PATCH, "/databases/$databaseId/collections/$collectionId/documents/$documentId/count/increment", array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
]), [
'value' => 0
]);
$this->assertEquals(400, $inc3['headers']['status-code']);
}