From 76e18a2226cb71440aca57d364f6e469294313f9 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 30 Jun 2026 10:47:08 +0530 Subject: [PATCH 1/4] Fix build failure error classification --- .../Modules/Functions/Workers/Builds.php | 9 ++++ src/Executor/Exception.php | 17 +++++++ src/Executor/Executor.php | 18 +++++--- .../Services/Sites/SitesCustomServerTest.php | 44 ++++++++++++++++++- 4 files changed, 80 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index fb4e691926..0f9a9dfdf8 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -17,6 +17,7 @@ use Appwrite\Usage\Context; use Appwrite\Utopia\Response\Model\Deployment; use Appwrite\Vcs\Comment; use Exception; +use Executor\Exception as ExecutorException; use Executor\Exception\Timeout as ExecutorTimeout; use Executor\Executor; use Swoole\Coroutine as Co; @@ -757,6 +758,14 @@ class Builds extends Action $span?->set('build.runtime.error_type', $error::class); $span?->set('build.runtime.error_message', $error->getMessage()); $err = new BuildException(type: AppwriteException::BUILD_TIMEOUT, previous: $error); + } catch (ExecutorException $error) { + $span?->set('build.runtime.error_type', $error::class); + $span?->set('build.runtime.error_message', $error->getMessage()); + $span?->set('build.runtime.executor_error_type', $error->getType()); + + $err = \in_array($error->getType(), [ExecutorException::BUILD_FAILED, ExecutorException::RUNTIME_FAILED], true) + ? new BuildException($error->getMessage(), previous: $error) + : $error; } catch (\Throwable $error) { $span?->set('build.runtime.error_type', $error::class); $span?->set('build.runtime.error_message', $error->getMessage()); diff --git a/src/Executor/Exception.php b/src/Executor/Exception.php index b799d22567..70499bd4c3 100644 --- a/src/Executor/Exception.php +++ b/src/Executor/Exception.php @@ -4,4 +4,21 @@ namespace Executor; class Exception extends \Exception { + public const string GENERAL_UNKNOWN = 'general_unknown'; + public const string BUILD_FAILED = 'build_failed'; + public const string RUNTIME_FAILED = 'runtime_failed'; + + public function __construct( + string $message = '', + int $code = 0, + ?\Throwable $previous = null, + private readonly string $type = self::GENERAL_UNKNOWN, + ) { + parent::__construct($message, $code, $previous); + } + + public function getType(): string + { + return $this->type; + } } diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index 53c86f1287..1ca966416b 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -105,8 +105,9 @@ class Executor $status = $response['headers']['status-code']; if ($status >= 400) { - $message = \is_string($response['body']) ? $response['body'] : $response['body']['message']; - throw new ExecutorException($message, $status); + $message = \is_string($response['body']) ? $response['body'] : ($response['body']['message'] ?? ''); + $type = \is_array($response['body']) ? ($response['body']['type'] ?? ExecutorException::GENERAL_UNKNOWN) : ExecutorException::GENERAL_UNKNOWN; + throw new ExecutorException($message, $status, type: $type); } return $response['body']; @@ -165,7 +166,8 @@ class Executor } if ($status >= 400) { - throw new ExecutorException($message, $status); + $type = \is_array($response['body']) ? ($response['body']['type'] ?? ExecutorException::GENERAL_UNKNOWN) : ExecutorException::GENERAL_UNKNOWN; + throw new ExecutorException($message, $status, type: $type); } return $response['body']; @@ -248,8 +250,9 @@ class Executor $status = $response['headers']['status-code']; if ($status >= 400) { - $message = \is_string($response['body']) ? $response['body'] : $response['body']['message']; - throw new ExecutorException($message, $status); + $message = \is_string($response['body']) ? $response['body'] : ($response['body']['message'] ?? ''); + $type = \is_array($response['body']) ? ($response['body']['type'] ?? ExecutorException::GENERAL_UNKNOWN) : ExecutorException::GENERAL_UNKNOWN; + throw new ExecutorException($message, $status, type: $type); } $headers = $response['body']['headers'] ?? []; @@ -282,8 +285,9 @@ class Executor $status = $response['headers']['status-code']; if ($status >= 400) { - $message = \is_string($response['body']) ? $response['body'] : $response['body']['message']; - throw new ExecutorException($message, $status); + $message = \is_string($response['body']) ? $response['body'] : ($response['body']['message'] ?? ''); + $type = \is_array($response['body']) ? ($response['body']['type'] ?? ExecutorException::GENERAL_UNKNOWN) : ExecutorException::GENERAL_UNKNOWN; + throw new ExecutorException($message, $status, type: $type); } return $response['body']; diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 7a5f578492..1732f1de24 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2954,7 +2954,49 @@ final class SitesCustomServerTest extends Scope $this->assertEventually(function () use ($siteId, $deploymentId) { $deployment = $this->getDeployment($siteId, $deploymentId); $this->assertEquals('failed', $deployment['body']['status'], 'Deployment status does not match: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); - $this->assertStringContainsString('Error:', (string) $deployment['body']['buildLogs'], 'Deployment logs do not match: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); + + $buildLogs = \preg_replace('/\x1b\[[0-9;]*m/', '', (string) $deployment['body']['buildLogs']) ?? ''; + $errorLogs = \array_values(\array_filter(\array_map( + static fn (string $line): string => \trim(\preg_replace('/^\[\d{2}:\d{2}:\d{2}\]\s+\[open-runtimes\]\s*/', '', $line) ?? ''), + \explode("\n", $buildLogs), + ), static fn (string $line): bool => \str_starts_with($line, 'Error:'))); + + $this->assertSame([ + "Error: No source code found. Ensure your source isn't empty.", + ], $errorLogs, 'Deployment logs should expose the exact user build error: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); + }, 100000, 500); + + $this->cleanupSite($siteId); + } + + public function testExitOneBuildShowsBuildFailure(): void + { + $siteId = $this->setupSite([ + 'siteId' => ID::unique(), + 'name' => 'Exit One Site', + 'framework' => 'other', + 'buildRuntime' => 'node-22', + 'outputDirectory' => './', + 'buildCommand' => 'exit 1', + ]); + + $deployment = $this->createDeployment($siteId, [ + 'code' => $this->packageSite('static-single-file'), + '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'], 'Deployment status does not match: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); + $this->assertStringContainsString( + 'Build command exited with code 1.', + (string) $deployment['body']['buildLogs'], + 'Deployment logs do not match: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT) + ); }, 100000, 500); $this->cleanupSite($siteId); From f1579227f04a6fe066da7f4cfc272ac0dda4a99f Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 30 Jun 2026 13:18:22 +0530 Subject: [PATCH 2/4] Prepare build errors for executor bump --- .../Platform/Modules/Functions/Workers/Builds.php | 2 +- src/Executor/Exception.php | 1 - tests/e2e/Services/Sites/SitesCustomServerTest.php | 11 +---------- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 0f9a9dfdf8..feba4797ab 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -763,7 +763,7 @@ class Builds extends Action $span?->set('build.runtime.error_message', $error->getMessage()); $span?->set('build.runtime.executor_error_type', $error->getType()); - $err = \in_array($error->getType(), [ExecutorException::BUILD_FAILED, ExecutorException::RUNTIME_FAILED], true) + $err = $error->getType() === ExecutorException::BUILD_FAILED ? new BuildException($error->getMessage(), previous: $error) : $error; } catch (\Throwable $error) { diff --git a/src/Executor/Exception.php b/src/Executor/Exception.php index 70499bd4c3..db40b4b745 100644 --- a/src/Executor/Exception.php +++ b/src/Executor/Exception.php @@ -6,7 +6,6 @@ class Exception extends \Exception { public const string GENERAL_UNKNOWN = 'general_unknown'; public const string BUILD_FAILED = 'build_failed'; - public const string RUNTIME_FAILED = 'runtime_failed'; public function __construct( string $message = '', diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 1732f1de24..39ee71081c 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2954,16 +2954,7 @@ final class SitesCustomServerTest extends Scope $this->assertEventually(function () use ($siteId, $deploymentId) { $deployment = $this->getDeployment($siteId, $deploymentId); $this->assertEquals('failed', $deployment['body']['status'], 'Deployment status does not match: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); - - $buildLogs = \preg_replace('/\x1b\[[0-9;]*m/', '', (string) $deployment['body']['buildLogs']) ?? ''; - $errorLogs = \array_values(\array_filter(\array_map( - static fn (string $line): string => \trim(\preg_replace('/^\[\d{2}:\d{2}:\d{2}\]\s+\[open-runtimes\]\s*/', '', $line) ?? ''), - \explode("\n", $buildLogs), - ), static fn (string $line): bool => \str_starts_with($line, 'Error:'))); - - $this->assertSame([ - "Error: No source code found. Ensure your source isn't empty.", - ], $errorLogs, 'Deployment logs should expose the exact user build error: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); + $this->assertStringContainsString('Error:', (string) $deployment['body']['buildLogs'], 'Deployment logs do not match: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); }, 100000, 500); $this->cleanupSite($siteId); From 55e63c53860e580f14dd450d4a004fe815b520bd Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 30 Jun 2026 14:47:01 +0530 Subject: [PATCH 3/4] Remove redundant build failure e2e --- .../Services/Sites/SitesCustomServerTest.php | 33 ------------------- 1 file changed, 33 deletions(-) diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 39ee71081c..7a5f578492 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2960,39 +2960,6 @@ final class SitesCustomServerTest extends Scope $this->cleanupSite($siteId); } - public function testExitOneBuildShowsBuildFailure(): void - { - $siteId = $this->setupSite([ - 'siteId' => ID::unique(), - 'name' => 'Exit One Site', - 'framework' => 'other', - 'buildRuntime' => 'node-22', - 'outputDirectory' => './', - 'buildCommand' => 'exit 1', - ]); - - $deployment = $this->createDeployment($siteId, [ - 'code' => $this->packageSite('static-single-file'), - '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'], 'Deployment status does not match: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); - $this->assertStringContainsString( - 'Build command exited with code 1.', - (string) $deployment['body']['buildLogs'], - 'Deployment logs do not match: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT) - ); - }, 100000, 500); - - $this->cleanupSite($siteId); - } - public function testSiteDeploymentRetention(): void { $siteIds = []; From 561d079d154656b35961afbe7c2fc51af0675b79 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 30 Jun 2026 15:06:24 +0530 Subject: [PATCH 4/4] Update executor to 0.25.2 --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9a43dc1dad..8b37d6b9ab 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1238,7 +1238,7 @@ services: max-file: "5" max-size: 10m stop_signal: SIGINT - image: openruntimes/executor:0.25.1 + image: openruntimes/executor:0.25.2 restart: unless-stopped networks: - appwrite