From 469ae3733d7cda992216744abe10c44b0f927728 Mon Sep 17 00:00:00 2001 From: Andreas Schempp Date: Tue, 29 Sep 2020 16:59:24 +0200 Subject: [PATCH] Improve cloud error handling --- api/TaskOperation/Composer/CloudOperation.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/api/TaskOperation/Composer/CloudOperation.php b/api/TaskOperation/Composer/CloudOperation.php index 76eb6e6b..4de70006 100644 --- a/api/TaskOperation/Composer/CloudOperation.php +++ b/api/TaskOperation/Composer/CloudOperation.php @@ -144,10 +144,11 @@ public function getDetails(): ?string public function getConsole(): ConsoleOutput { + $console = new ConsoleOutput(); $job = $this->getCurrentJob(); if ($this->exception instanceof CloudException) { - return (new ConsoleOutput())->add( + return $console->add( sprintf( "> The Composer Resolver Cloud failed with status code %s\n\n %s", $this->exception->getStatusCode(), @@ -157,18 +158,21 @@ public function getConsole(): ConsoleOutput } if ($this->exception instanceof RequestException && 404 === $this->exception->getStatusCode()) { - return (new ConsoleOutput())->add(self::CLOUD_ERROR); + return $console->add(self::CLOUD_ERROR); } if ($this->exception instanceof \Exception) { - return (new ConsoleOutput())->add($this->exception->getMessage()); + return $console->add($this->exception->getMessage()); } if (!$job instanceof CloudJob) { - return new ConsoleOutput(); + if ($this->hasError()) { + $console->add(self::CLOUD_ERROR); + } + + return $console; } - $console = new ConsoleOutput(); $title = '> Resolving dependencies using Composer Cloud '.$job->getVersion(); // $title .= "\n!!! Current server is sponsored by: ".$job->getSponsor()." !!!\n"; @@ -248,7 +252,7 @@ public function run(): void // Retry to create Cloud job, the first request always fails on XAMPP for unknown reason $attempts = $this->taskConfig->getState('cloud-job-attempts', 0); - if ($attempts >= 2) { + if ($attempts >= 5) { $this->taskConfig->setState('cloud-job-successful', false); $this->output = self::CLOUD_ERROR; @@ -308,6 +312,10 @@ private function getCurrentJob(): ?CloudJob return $this->job; } + if (null === $this->taskConfig->getState('cloud-job')) { + return null; + } + try { if ($content = $this->taskConfig->getState('cloud-job-status')) { $this->job = new CloudJob(JsonFile::parseJson($content));