From bd18edc197af640253bc58cbf668ed2491c7d352 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 24 Mar 2025 15:50:25 +0530 Subject: [PATCH 1/3] If build has failed, show correct error page --- app/config/errors.php | 5 +++++ app/controllers/general.php | 6 +++++- src/Appwrite/Extend/Exception.php | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/config/errors.php b/app/config/errors.php index 58e95cf5d4..c3b791f613 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -580,6 +580,11 @@ return [ 'description' => 'Build with the requested ID is already completed and cannot be canceled.', 'code' => 400, ], + Exception::BUILD_FAILED => [ + 'name' => Exception::BUILD_FAILED, + 'description' => 'Build with the requested ID failed. Please check the logs for more information.', + 'code' => 400, + ], /** Deployments */ Exception::DEPLOYMENT_NOT_FOUND => [ diff --git a/app/controllers/general.php b/app/controllers/general.php index 3afe1d8a3d..c378ba817a 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -269,10 +269,14 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw throw new AppwriteException(AppwriteException::FUNCTION_RUNTIME_UNSUPPORTED, 'Runtime "' . $resource->getAttribute('runtime', '') . '" is not supported'); } - if ($deployment->getAttribute('status') !== 'ready') { + if ($deployment->getAttribute('status') === 'waiting' || $deployment->getAttribute('status') === 'processing' || $deployment->getAttribute('status') === 'building') { throw new AppwriteException(AppwriteException::BUILD_NOT_READY); } + if ($deployment->getAttribute('status') === 'failed') { + throw new AppwriteException(AppwriteException::BUILD_FAILED); + } + if ($type === 'function') { $permissions = $resource->getAttribute('execute'); if (!(\in_array('any', $permissions)) && !(\in_array('guests', $permissions))) { diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index db8f5f7134..338da29403 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -174,6 +174,7 @@ class Exception extends \Exception public const BUILD_NOT_READY = 'build_not_ready'; public const BUILD_IN_PROGRESS = 'build_in_progress'; public const BUILD_ALREADY_COMPLETED = 'build_already_completed'; + public const BUILD_FAILED = 'build_failed'; /** Execution */ public const EXECUTION_NOT_FOUND = 'execution_not_found'; From 3b9318c2fcd9c60cd473bbc8735410a814998091 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 26 Mar 2025 16:52:32 +0530 Subject: [PATCH 2/3] Add tests --- app/controllers/general.php | 12 +++--- .../Services/Sites/SitesCustomServerTest.php | 37 +++++++++++++++++++ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index e66379d40d..87a9c420c7 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -269,12 +269,12 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw throw new AppwriteException(AppwriteException::FUNCTION_RUNTIME_UNSUPPORTED, 'Runtime "' . $resource->getAttribute('runtime', '') . '" is not supported'); } - if ($deployment->getAttribute('status') === 'waiting' || $deployment->getAttribute('status') === 'processing' || $deployment->getAttribute('status') === 'building') { - throw new AppwriteException(AppwriteException::BUILD_NOT_READY); - } - - if ($deployment->getAttribute('status') === 'failed') { - throw new AppwriteException(AppwriteException::BUILD_FAILED); + if ($deployment->getAttribute('status') !== 'ready') { + if ($deployment->getAttribute('status') === 'failed') { + throw new AppwriteException(AppwriteException::BUILD_FAILED); + } else { + throw new AppwriteException(AppwriteException::BUILD_NOT_READY); + } } if ($type === 'function') { diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index d0cc3b5ba5..4d0ef66112 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2393,4 +2393,41 @@ class SitesCustomServerTest extends Scope $this->cleanupSite($siteId); } + + public function testDomainForFailedDeloyment(): void + { + $siteId = $this->setupSite([ + 'siteId' => ID::unique(), + 'name' => 'Test Site', + 'framework' => 'astro', + 'buildRuntime' => 'node-22', + 'buildCommand' => 'cd random' + ]); + + $this->assertNotEmpty($siteId); + + $domain = $this->setupSiteDomain($siteId); + $this->assertNotEmpty($domain); + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://' . $domain); + + $deployment = $this->createDeployment($siteId, [ + 'code' => $this->packageSite('astro'), + 'activate' => true + ]); + $this->assertEquals(202, $deployment['headers']['status-code']); + + $deploymentId = $deployment['body']['$id']; + $this->assertNotEmpty($deploymentId); + + $this->assertEventually(function () use ($siteId, $deploymentId) { + $deployment = $this->getDeployment($siteId, $deploymentId); + $this->assertEquals('failed', $deployment['body']['status'], json_encode($deployment['body'], JSON_PRETTY_PRINT)); + }, 100000, 500); + + $response = $proxyClient->call(Client::METHOD_GET, '/'); + $this->assertStringContainsString('Build with the requested ID failed. Please check the logs for more information.', $response['body']); + + $this->cleanupSite($siteId); + } } From 583a18dcd76d62c3eecc4c2f7d0b17ac9af49db0 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 26 Mar 2025 17:06:19 +0530 Subject: [PATCH 3/3] Update assertion --- tests/e2e/Services/Sites/SitesCustomServerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 4d0ef66112..bf9eb0dc29 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2426,7 +2426,7 @@ class SitesCustomServerTest extends Scope }, 100000, 500); $response = $proxyClient->call(Client::METHOD_GET, '/'); - $this->assertStringContainsString('Build with the requested ID failed. Please check the logs for more information.', $response['body']); + $this->assertStringContainsString('build_failed', $response['body']); $this->cleanupSite($siteId); }