Fix build failure error classification

This commit is contained in:
Chirag Aggarwal committed 2026-06-30 11:26:30 +05:30
1 parent 386a6b13cf
commit 76e18a2226
4 files changed
+80 -8

No files matched your search

@@ -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());
+17
View File
@@ -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;
}
}
+11 -7
View File
@@ -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'];
@@ -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);