diff --git a/docker-compose.yml b/docker-compose.yml index 7ad12e7ddf..71457cc82e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1194,7 +1194,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 diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index fb4e691926..feba4797ab 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 = $error->getType() === ExecutorException::BUILD_FAILED + ? 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..db40b4b745 100644 --- a/src/Executor/Exception.php +++ b/src/Executor/Exception.php @@ -4,4 +4,20 @@ namespace Executor; class Exception extends \Exception { + public const string GENERAL_UNKNOWN = 'general_unknown'; + public const string BUILD_FAILED = 'build_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'];