mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 00:49:02 +00:00
Add improved error handling for SDK Class
This commit is contained in:
parent
6a782ce373
commit
0d6095ba18
3 changed files with 46 additions and 30 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Appwrite\SDK\Method;
|
||||
use Appwrite\Utopia\Request;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Swoole\Constant;
|
||||
|
|
@ -335,4 +336,5 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo
|
|||
}
|
||||
});
|
||||
|
||||
Method::finaliseInitialization();
|
||||
$http->start();
|
||||
|
|
|
|||
42
composer.lock
generated
42
composer.lock
generated
|
|
@ -4807,16 +4807,16 @@
|
|||
"packages-dev": [
|
||||
{
|
||||
"name": "appwrite/sdk-generator",
|
||||
"version": "0.39.27",
|
||||
"version": "0.39.28",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/appwrite/sdk-generator.git",
|
||||
"reference": "27d8ecde30e40cbfe1124cc0430c406d3e144849"
|
||||
"reference": "6ff467858fe418e364460da905139216570a5d5e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/27d8ecde30e40cbfe1124cc0430c406d3e144849",
|
||||
"reference": "27d8ecde30e40cbfe1124cc0430c406d3e144849",
|
||||
"url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/6ff467858fe418e364460da905139216570a5d5e",
|
||||
"reference": "6ff467858fe418e364460da905139216570a5d5e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -4852,9 +4852,9 @@
|
|||
"description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms",
|
||||
"support": {
|
||||
"issues": "https://github.com/appwrite/sdk-generator/issues",
|
||||
"source": "https://github.com/appwrite/sdk-generator/tree/0.39.27"
|
||||
"source": "https://github.com/appwrite/sdk-generator/tree/0.39.28"
|
||||
},
|
||||
"time": "2024-12-16T11:32:02+00:00"
|
||||
"time": "2024-12-30T11:17:25+00:00"
|
||||
},
|
||||
{
|
||||
"name": "doctrine/annotations",
|
||||
|
|
@ -5126,16 +5126,16 @@
|
|||
},
|
||||
{
|
||||
"name": "laravel/pint",
|
||||
"version": "v1.18.3",
|
||||
"version": "v1.19.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/pint.git",
|
||||
"reference": "cef51821608239040ab841ad6e1c6ae502ae3026"
|
||||
"reference": "8169513746e1bac70c85d6ea1524d9225d4886f0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/pint/zipball/cef51821608239040ab841ad6e1c6ae502ae3026",
|
||||
"reference": "cef51821608239040ab841ad6e1c6ae502ae3026",
|
||||
"url": "https://api.github.com/repos/laravel/pint/zipball/8169513746e1bac70c85d6ea1524d9225d4886f0",
|
||||
"reference": "8169513746e1bac70c85d6ea1524d9225d4886f0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -5146,10 +5146,10 @@
|
|||
"php": "^8.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "^3.65.0",
|
||||
"illuminate/view": "^10.48.24",
|
||||
"larastan/larastan": "^2.9.11",
|
||||
"laravel-zero/framework": "^10.4.0",
|
||||
"friendsofphp/php-cs-fixer": "^3.66.0",
|
||||
"illuminate/view": "^10.48.25",
|
||||
"larastan/larastan": "^2.9.12",
|
||||
"laravel-zero/framework": "^10.48.25",
|
||||
"mockery/mockery": "^1.6.12",
|
||||
"nunomaduro/termwind": "^1.17.0",
|
||||
"pestphp/pest": "^2.36.0"
|
||||
|
|
@ -5188,7 +5188,7 @@
|
|||
"issues": "https://github.com/laravel/pint/issues",
|
||||
"source": "https://github.com/laravel/pint"
|
||||
},
|
||||
"time": "2024-11-26T15:34:00+00:00"
|
||||
"time": "2024-12-30T16:20:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "matthiasmullie/minify",
|
||||
|
|
@ -5376,16 +5376,16 @@
|
|||
},
|
||||
{
|
||||
"name": "nikic/php-parser",
|
||||
"version": "v5.3.1",
|
||||
"version": "v5.4.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nikic/PHP-Parser.git",
|
||||
"reference": "8eea230464783aa9671db8eea6f8c6ac5285794b"
|
||||
"reference": "447a020a1f875a434d62f2a401f53b82a396e494"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/8eea230464783aa9671db8eea6f8c6ac5285794b",
|
||||
"reference": "8eea230464783aa9671db8eea6f8c6ac5285794b",
|
||||
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/447a020a1f875a434d62f2a401f53b82a396e494",
|
||||
"reference": "447a020a1f875a434d62f2a401f53b82a396e494",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -5428,9 +5428,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/nikic/PHP-Parser/issues",
|
||||
"source": "https://github.com/nikic/PHP-Parser/tree/v5.3.1"
|
||||
"source": "https://github.com/nikic/PHP-Parser/tree/v5.4.0"
|
||||
},
|
||||
"time": "2024-10-08T18:51:32+00:00"
|
||||
"time": "2024-12-30T11:07:19+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phar-io/manifest",
|
||||
|
|
|
|||
|
|
@ -37,6 +37,11 @@ class Method
|
|||
{
|
||||
public static array $knownMethods = [];
|
||||
|
||||
//Tmp
|
||||
public static array $knownMissingDescriptions = [];
|
||||
|
||||
public static array $exceptions = [];
|
||||
|
||||
/**
|
||||
* @var array<Multiplex>
|
||||
*/
|
||||
|
|
@ -85,8 +90,7 @@ class Method
|
|||
) {
|
||||
$this->validateMethod($name, $namespace);
|
||||
$this->validateAuthTypes($auth);
|
||||
// Disabled for now, will be enabled later
|
||||
// $this->validateDesc($description);
|
||||
$this->validateDesc($description);
|
||||
|
||||
foreach ($responses as $response) {
|
||||
/** @var \Appwrite\SDK\Response $response */
|
||||
|
|
@ -95,7 +99,7 @@ class Method
|
|||
// No content check
|
||||
if ($response->getCode() === 204) {
|
||||
if ($response->getModel() !== Response::MODEL_NONE) {
|
||||
throw new \Exception("Error with {$this->getDebugName()} method: Response code 204 must have response model 'none'");
|
||||
self::$exceptions[] = "Error with {$this->getDebugName()} method: Response code 204 must have response model 'none'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -109,7 +113,7 @@ class Method
|
|||
private function validateMethod(string $name, string $namespace): void
|
||||
{
|
||||
if (\in_array($this->getDebugName(), self::$knownMethods)) {
|
||||
throw new \Exception('Method ' . $name . ' already exists in namespace ' . $namespace);
|
||||
self::$exceptions[] = "Error with {$this->getDebugName()} method: Method already exists in namespace {$namespace}";
|
||||
}
|
||||
|
||||
self::$knownMethods[] = $this->getDebugName();
|
||||
|
|
@ -119,7 +123,7 @@ class Method
|
|||
{
|
||||
foreach ($authTypes as $authType) {
|
||||
if (!($authType instanceof AuthType)) {
|
||||
throw new \Exception("Error with {$this->getDebugName()} method: Invalid auth type");
|
||||
self::$exceptions[] = "Error with {$this->getDebugName()} method: Invalid auth type";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -127,13 +131,15 @@ class Method
|
|||
private function validateDesc(string $desc): void
|
||||
{
|
||||
if (empty($desc)) {
|
||||
throw new \Exception("Error with {$this->getDebugName()} method: Description file not set");
|
||||
self::$exceptions[] = "Error with {$this->getDebugName()} method: Description label is empty";
|
||||
return;
|
||||
}
|
||||
|
||||
$descPath = \realpath(__DIR__ . '/../../../' . $desc);
|
||||
|
||||
if (!\file_exists($descPath)) {
|
||||
throw new \Exception("Error with {$this->getDebugName()} method: Description file not found at {$descPath}");
|
||||
self::$exceptions[] = "Error with {$this->getDebugName()} method: Description file not found at {$desc}";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -146,7 +152,7 @@ class Method
|
|||
try {
|
||||
$response->getModel($model);
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception("Error with {$this->getDebugName()} method: Invalid response model, make sure the model has been defined in Response.php");
|
||||
self::$exceptions[] = "Error with {$this->getDebugName()} method: Invalid response model, make sure the model has been defined in Response.php";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -156,7 +162,7 @@ class Method
|
|||
try {
|
||||
$response->getModel($responseModel);
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception("Error with {$this->getDebugName()} method: Invalid response model, make sure the model has been defined in Response.php");
|
||||
self::$exceptions[] = "Error with {$this->getDebugName()} method: Invalid response model, make sure the model has been defined in Response.php";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -239,4 +245,12 @@ class Method
|
|||
{
|
||||
return $this->multiplex;
|
||||
}
|
||||
|
||||
// Throw any errors that were found during initialization
|
||||
static function finaliseInitialization(): void
|
||||
{
|
||||
if (!empty(self::$exceptions)) {
|
||||
throw new \Exception('Errors found during SDK initialization:' . PHP_EOL . implode(PHP_EOL, self::$exceptions));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue